public class WindMov : MonoBehaviour
{
public GameObject wind;
public float mSpeed = 5f;
public Transform currentPosition;
public Transform[] points;
public int pointSelection = 0;
public bool forward = true;
// Start is called before the first frame update
void Start()
{
currentPosition = points[pointSelection];
}
private void Update()
{
if (wind.transform.position == currentPosition.position)
{
if (forward == true)
{
pointSelection++;
}
else
{
pointSelection--;
}
if(pointSelection == points.Length && forward == true)
{
forward = false;
}else if (currentPosition.position == points[0].position && forward == false)
{
forward = true;
}
currentPosition = points[pointSelection];
}
}
void FixedUpdate()
{
wind.transform.position = Vector3.MoveTowards(wind.transform.position, currentPosition.position, Time.deltaTime * mSpeed);
}
}
hi, I’m working on this script, that seems that is working perfectly, but, it displays me an error in the console, the script its suppose to make the gameObject to go along a route and after reaching the end, goes backwards just to start again, and it totally works, but it bugs me that it displays this error, can someone enlighten me about how to fix it? it seems to display whenever it changes between true and false on the boolean variable, each time it reachs one end of the array or the other
IndexOutOfRangeException: Index was outside the bounds of the array.
WindMov.Update () (at Assets/Scripts/Elements/WindMov.cs:47)