// Check the state corresponding transitions to other FSM states. public void CheckTransitions(StateController controller) { // First decisions has precedence over the last ones. for (int i = 0; i < transitions.Length; i++) { bool decision = transitions[i].decision.Decide(controller); if (decision) { // Go to true state. controller.TransitionToState(transitions[i].trueState, transitions[i].decision); } else { // Go to false state. controller.TransitionToState(transitions[i].falseState, transitions[i].decision); } // If a transition was performed to another state, trigger on enable for all actions of new state. if (controller.currentState != this) { controller.currentState.OnEnableActions(controller); // No need to check remaining transitions. break; } } }