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 Attack state and more


The Attack state is entered when the zombie arrives within the attack distance to the player. During this state, the zombie repeatedly attacks the player until either the player dies or the player leaves the attack distance:

Attack state

Consider the following code:

    //------------------------------------ 
    public IEnumerator StateAttack() 
    { 
        //Run attack animation 
        ThisAnimator.SetInteger("AnimState", (int) ActiveState); 
 
        //While in idle state 
        while(ActiveState == AISTATE.ATTACK) 
        { 
            //Look at player 
            Vector3 PlanarPosition = new Vector3(PlayerTransform.position.x, ThisTransform.position.y, PlayerTransform.position.z); 
            ThisTransform.LookAt(PlanarPosition, ThisTransform.up); 
 
            //Get distance between enemy and player 
            float Distance = Vector3.Distance(PlayerTransform.position...