IndexOutofRangeException error

Help with patrol. We want him to move from point A and point B consistently without stopping. This is one of our first games to build. We are getting an Array index is out of range error. Patrol.Update () (at Assets/Scripts/Patrol.cs.18):

The only thing that could generate a index out of range in that line is patrolpoints[currentpoint], so set a Debug.Log(currentpoint) before, to see if the value is greater than patrolpoints length, if so find all references to currentpoint and try to locate where it could be extrapolating its limit.

Also you could change currentpoint to a property that will always circle between a min and a max.

private int _currentpoint;
public int currentpoint 
{
    get { return  _currentpoint; }
    set{   _currentpoint = ClampCircle(value, 0, patrolpoints.Length - 1); }
}

public static int ClampCircle(int p_value, int p_min, int p_max)
{
        if (p_value > p_max)
        {
            p_value = p_min;
        }
        else if (p_value < p_min)
        {
            p_value = p_max;
        }

        return p_value;
}

This way you don’t have to make if statements every time you change the value of currentpoint.

@Pugninjas