Hi,
So, I have an GameObject that I want to change his position multiple times during the time. I don’t want random positions, I want to be able to define all the exact positions of the GameObject. How do I store those positions? In an array, list? And how do I change between them? I have a boolean and I want that every single time it stays true to change to the next position. How do I do that? Thanks.
Something like this?
float timer = 0f;
int current = 0;
Vector3[] positions = {
new Vector3(-20.0f, 0, 0), new Vector3(-10.0f, 0, 0),
new Vector3(0.0f, 0, 0), new Vector3(10.0f, 0, 0), new Vector3(20.0f, 0, 0)
};
void Update()
{
timer += Time.deltaTime;
if(timer > 4.0f) //change position every 4 s
{
timer = 0;
transform.position = positions[current];
current++;
if (current >= positions.Length) current = 0;
}
}