- Home /
Question by
JoshMBeyer · Sep 03, 2014 at 03:02 AM ·
c#arrayplatformincrement
Need help fixing this script again... Sorry guys.
I am trying to get it to where the object moves to all the points, then when reaching the last point, it goes backwards through the points again, this time from the last one to the first. I know what the issue is, I just can't seem to fix it. Its working fine going from 0 - 3 but when it reaches the last point, it goes out of bounds instead of switching order and going backwards.
int p = points.Length;
Debug.Log(currentPoint);
Debug.Log(switchIt);
destination = points[currentPoint];
if (currentPoint == p) { switchIt = true; }
if (currentPoint == 0) { switchIt = false; }
//So currentPoints isn't greater than points length. Or less than 0.
if (currentPoint >= points.Length) { switchIt = true; }
if(currentPoint <= 0) {currentPoint = 0;}
if (go && enableMultiPoints)
{
float step = speed * Time.deltaTime;
transform.position = Vector3.MoveTowards(transform.position, destination.position, step);
if (transform.position == destination.position && !switchIt)
{
currentPoint++;
}else if (transform.position == destination.position && switchIt)
{
currentPoint--;
}
}
Comment