Waypoints and out of range problem.[Solved]

Ok I have this AI over here thats a bit retarded at the moment and this is caused by it not being able to loop its waypoints.

As in it gets to the end of the last way point fine but then throws up the out of range exception. I need a way for it to make the current way point the first in the array again when it gets to the end.

Can you help me with a solution, I have been trying everything and they not working here is the code that so far.

 	if(inWaypointPath == true && curWaypointDist < 2){

             currentWaypoint = currentWaypoint+1;

		
		}
// this is what is not working... This is just one way I tried but failed.
	if(currentWaypoint > wayPoints.Count){				
                
			currentWaypoint = 0;

		 }

Thanks.

Hi, @betaFlux is correct if you are using the array as expected. You are checking if the incremented index is past the last index in the array and then wrapping it around to the first index (0). The problem is that this will not reset the index to 0 until it is greater than the count but wayPoints[wayPoints.Count] will be out of bounds due to indexing from 0.

    if(currentWaypoint >= wayPoints.Count)
    {              
        currentWaypoint = 0;
    }

I hope that helps =D