Book Image

Mastering Unity 5.x

By : Alan Thorn
Book Image

Mastering Unity 5.x

By: Alan Thorn

Overview of this book

Mastering Unity 5.x is for developers wishing to optimize the features of Unity 5.x. With an in-depth focus on a practical project, learn all about Unity architecture and impressive animation techniques. With this book, produce fun games with confidence.
Table of Contents (16 chapters)
Mastering Unity 5.x
Credits
About the Author
Acknowledgment
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

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:

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) 
            yield return null; 
 
        //While in chase state 
        while(ActiveState == AISTATE.CHASE) 
        { 
            if (ThisAgent.remainingDistance &lt...