Developing the Chase state

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

Chase state

The following is the Chase coroutine (for the Chase state). It contains some interesting features, detailed 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) ...

Get Mastering Unity 2017 Game Development with C# - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.