i want my obs1 which is a game object to practicly teleport to a another game object and then move towards a randomly selected object from an array of gameobjects but it shows me the error from the title and i dont know how to solve it can someone help me?
public class obs1script : MonoBehaviour
{
public GameObject[] location1;
public GameObject[] location2;
public float firstphase = 45f;
public float first;
int index1,index2;
Vector2 target;
void Start()
{
first = Time.time + firstphase;
}
void FixedUpdate()
{
index1 = Random.Range(0,location1.Length);
transform.position = new Vector2(location1[index1].X,location1[index1].Y);
index2 = Random.Range(0,location2.Length);
target = location2[index2].transform.position;
transform.position = Vector2.MoveTowards(transform.position,target,0.1f);
}
}
the problem is here: transform.position = new Vector2(location1[index1].X,location1[index1].Y);
index2 = Random.Range(0,location2.Length);
↧