O'Reilly logo

Mastering Unity 5.x 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

Developing the Chase state

The Chase state occurs when the NPC is following and moving towards the player. In Dead Keys, this happens whenever the scene camera moves into a trigger volume or area where zombies are waiting:

Developing the Chase state

Chase state

The following is the Chase coroutine (for the Chase state). It contains some interesting features, considered further in the comments section:

 //------------------------------------ public IEnumerator StateChase() { //Run chase animation ThisAnimator.SetInteger("AnimState", (int) ActiveState); //Set destination ThisAgent.SetDestination (PlayerTransform.position); //Wait until path is calculated while (!ThisAgent.hasPath) ...

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