I made a camera scrolling script to scroll my camera Each time the player finished a section of the level. I stored all the positions of sections of the level in a vector2 array. The script in the inspector looks like this:
This is the script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraMove : MonoBehaviour {
public Vector2[] position_list;
public bool trigger_next_position;
public float camera_movement_speed ;
private int current_position = 0;
private bool in_motion;
void Start () {
transform.position = position_list [current_position];
Vector3 curr_calc_position= transform.position;
curr_calc_position.z -= 1;
transform.position = curr_calc_position;
}
void move_position(){
Vector2 current_position = transform.position;
Vector2 TargetPos = position_list[current_position];
float target_y = (float)TargetPos.y;
float target_x = (float)TargetPos.x;
if (current_position.x > target_x) {
current_position.x -= camera_movement_speed * Time.deltaTime;
} else if (current_position.x < target_x) {
current_position.x += camera_movement_speed * Time.deltaTime;
}
if (current_position.y > target_y) {
current_position.y -= camera_movement_speed * Time.deltaTime;
} else if (current_position.y < target_y) {
current_position.y += camera_movement_speed * Time.deltaTime;
}
if (current_position.x == target_x) {
if (current_position.y == target_y) {
in_motion = false;
}
}
}
void Update () {
if (trigger_next_position) {
trigger_next_position = false;
current_position += 1;
in_motion = true;
}
if (in_motion) {
move_position ();
}
}
}
I end up getting this error:
Assets/CommonAssets/Scripts/Camera/CameraMove.cs(23,37): error CS0029: Cannot implicitly convert type `UnityEngine.Vector2' to `int'
I fail to understand why this keeps happening if any of you could help it would be appreciated.
↧