Пример #1
0
    /// <summary>
    /// Sets new state based off input transition
    /// </summary>
    /// <param name="trans">Transition to be set to given state</param>
    public void SetTransition(FSMTransitions trans)
    {
        if (trans == FSMTransitions.none)
        {
            Debug.LogError("Null transition is not allowed");
            return;
        }
        FSMStateID newID = currentState.CheckTransition(trans);

        if (newID == FSMStateID.none)
        {
            Debug.LogError("There is no state bound to " + trans.ToString());
            return;
        }
        foreach (var state in FSMStates)
        {
            if (newID == state.StateID)
            {
                Debug.Log("State changed to " + newID.ToString());
                currentState.OnStateExit(playerTransform, gameObject);

                currentState = state;
                currentState.OnStateEnter(playerTransform, gameObject);
                return;
            }
        }
        Debug.LogError("Unidentified error with state transition");
    }
Пример #2
0
 private void Update()
 {
     currentState.UpdateState();
     currentState.CheckTransition();
 }