private void SwitchToNewState(StateType nextState) { if (availableStates.ContainsKey(nextState)) { StateType oldState = currentState.type; currentState = availableStates[nextState]; currentState.Activate(); //Debug.Log(currentState.StateGameObject.name + " state: " + oldState + " -> " + currentState.type); } }
private void Awake() { rBody2D = GetComponent <Rigidbody2D>(); playerAnimator = GetComponent <Animator>(); sprite = GetComponent <SpriteRenderer>(); states = new List <BaseState>(GetComponentsInChildren <BaseState>(true)); states.ForEach(_state => { _state.Setup(rBody2D, sprite, playerAnimator); _state.NextStateAction = OnNextStateRequest; }); currentState = states.Find(_state => _state.PlayerState == PlayerState.Idle); currentState.Activate(); }
public void OnNextStateRequest(PlayerState _state) { currentState.Diactivate(); currentState = states.Find(_s => _s.PlayerState == _state); currentState.Activate(); }