A generic character with multiple states like "Idle, Walk, Running, Air"
-
In the class PlayerState, add the new state to the enum public enum State { Idle, Walk, Running, Air, NewState };
-
Create a new class called PlayerStateNewState which inherit from PlayerState
-
In the inspector, locate the "stateTransform" of the StateMachine and add your new state as a component
-
In PlayerStateMachine, in the function InitialiseStateDictionary(), add InitialiseState(PlayerState.State.NewState, stateTransform.GetComponent());
-
In other state, call SetState(PlayerState.NewState) when you see fit!
Each time a new State is set, the previous will call "OnEnd()", so don't use "OnEnd()" to leave the currentState. The new state will call "OnStart()"
"PlayerInput" will convert your input to match the view of the camera. Pressing "Up" will make you walk forward considering the camera view.
"PlayerAnimationListener" will bind animations with state, this is helpful if you want your code in the state to stay clean and cohesive.