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 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, ...

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