O'Reilly logo

Mastering Unity Scripting by Alan Thorn

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating the Patrol state

In the Patrol state, the enemy should wander the environment and look for the player. This state can be entered from the Idle state, after the idle animation is completed, and also from the Chase state, if the enemy loses sight of the player during a chase. Patrol involves a looping logic. Specifically, the enemy should pick a random destination somewhere on the navigation mesh and then travel to that destination. When the destination is reached, the process should repeat and so on. The only condition that causes the enemy to leave this state is a sighting of the player, which demands a Chase state.

Though simple to explain, this state relies on two more complex issues: first, a random location must be selected and second, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required