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 state structure


The zombie character has four main states, and therefore the zombie FSM must decide which state should be activated at any time, and which logic should govern the relationship between states. To start implementing the FSM, we'll write the following code, to create a state change function which sets the FSM to a specified state from any of the four available states. Comments follow the code:

//------------------------------------ 
using UnityEngine; 
using System.Collections; 
using UnityEngine.EventSystems; 
using UnityEngine.Events; 
using UnityEngine.UI; 
//------------------------------------ 
public class AIEnemy : MonoBehaviour 
{ 
    //------------------------------------ 
    public enum AISTATE {IDLE = 0, CHASE = 1, ATTACK = 2, DEAD = 3}; 
 
    [SerializeField] 
    private AISTATE mActiveState = AISTATE.IDLE; 
 
    public AISTATE ActiveState 
    { 
        get{ return...