if(wayPointIndex == patrolWayPoints.Length-1)
{
wayPointIndex = 0;
}
I've almost finished this tutorial and I have a quick question about the above code. It says that if the `wayPointIndex == patrolWayPoints.Length -1` then the last waypoint will be set to 0 in the wayPointIndex. But if the enemy has 4 wayPoints and you subtract 1, wouldn't that set the third wayPoint to zero?
void Patrolling()
{
nav.speed = patrolSpeed;
if(nav.destination == lastPlayerSighting.resetPosition || nav.remainingDistance < nav.stoppingDistance)
{
patrolTimer += Time.deltaTime;
if(patrolTimer >= patrolWaitTime)
{
if(wayPointIndex == patrolWayPoints.Length-1)
{
wayPointIndex = 0;
}
else
{
wayPointIndex++;
patrolTimer = 0f;
}
}
}
else
{
patrolTimer = 0f;
}
nav.destination = patrolWayPoints[wayPointIndex].position; //if we currently have no destination then set it to our wayPoints
}
}
↧