private void Update() { CheckPlayerState(); stateName = currentState.ToString(); totalTime += Time.deltaTime; if (totalTime >= 0.5f) { // check and apply transitions, return a list of actions ITransition triggered = null; // store first transition that triggers if (currentState != null) { foreach (ITransition t in currentState.GetTransitions()) { if (t.IsTriggered()) { triggered = t; break; } } // check if we have a transition to fire if (triggered != null) { targetState = triggered.GetTargetState(); actions = currentState.GetExitActions(); // actions += triggered.getActions() IAction[] newActions = new IAction[actions.Length + triggered.GetActions().Length]; actions.CopyTo(newActions, 0); triggered.GetActions().CopyTo(newActions, actions.Length); actions = newActions; newActions = null; // actions += targetState.getEntryActions() newActions = new IAction[actions.Length + targetState.GetEntryActions().Length]; actions.CopyTo(newActions, 0); targetState.GetEntryActions().CopyTo(newActions, actions.Length); currentState = targetState; currentState.GetActions(); } else { currentState.GetActions(); } } totalTime = 0.0f; } }