Quantcast
Channel: Latest Questions by Fox-Handler
Viewing all articles
Browse latest Browse all 90

The Last Element in an Array?

$
0
0
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 } }

Viewing all articles
Browse latest Browse all 90

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>