We will create a state that is capable of holding internal states, in order to develop multilevel hierarchical state machines:
- First, let's create the StateHighLevel class deriving from State, as shown in the following code:
using UnityEngine; using System.Collections; using System.Collections.Generic; public class StateHighLevel : State { }
- Next, add the new member variables to control the internal states, as demonstrated in the following code:
public List<State> states; public State stateInitial; protected State stateCurrent;
- Then, we override the initialization function, as shown in the following code:
public override void OnEnable() { if (stateCurrent == null) stateCurrent = stateInitial; stateCurrent.enabled = ...