- Home /
How to apply variable to next item in array?
I want to make it to where destination is points[0]. if transform.position == points[1], then destination = points[2]. if the object is at the same position as destination, destination is set to the next point in the points[] array. How would i do this since the amount of points[] can varry?
int p = points.Length;
if (go && p > 2)
{
float step = speed * Time.deltaTime;
transform.position = Vector3.MoveTowards(transform.position, destination.position, step);
if (transform.position == destination.position)
{
//var cPoint = points[0];
destination = points[1];
}
}
Answer by JoshMBeyer · Sep 03, 2014 at 02:21 AM
I solved the issue by creating an int currentPoints and placing it inside[] like this. points[currentPoint] and then incrementing it each time the object reached the desination. currentpoints++
sir josh can you show a pseudocode or any samples of how you did it
Your answer
Follow this Question
Related Questions
Unity Array.Length Bug/Problem? 1 Answer
Array exists, but won't give length??? 1 Answer
Arrays and For loops question 1 Answer
c# array size doesn't grow past 10 (bracket initialization) 2 Answers
get length of array c# 1 Answer