I’ve watched a couple of videos on state machines and I’m now trying to implement one with my movement code, however, I’m unsure how I should go about doing so.
Basically in the tutorial, I watched it showed to have a state manager script, a base state script and then a script for each state you want and this seems to be the basic setup for a state machine(?) anyways though this is the code for the state manager.
public class PlayerStateManager : MonoBehaviour
{
PlayerBaseState currentState;
public PlayerIdleState idleState = new PlayerIdleState();
public PlayerRunState runState = new PlayerRunState();
public PlayerJumpState jumpState = new PlayerJumpState();
public PlayerLandState landState = new PlayerLandState();
public PlayerFallState fallState = new PlayerFallState();
void Start()
{
currentState = idleState;
currentState.EnterState(this);
}
void Update()
{
currentState.UpdateState(this);
}
public void SwitchState(PlayerBaseState state)
{
currentState = state;
state.EnterState(this);
}
}
And now what I’m unsure about is should I make another script that handles input and then when the jump key is pressed I can call the SwitchState method or should I put all of the input code in the state manager? Hopefully that made sense lol.