19 lines
281 B
C#
19 lines
281 B
C#
public class StateMachine
|
|
{
|
|
private IState currentState;
|
|
|
|
public IState Current => currentState;
|
|
|
|
public void ChangeState(IState newState)
|
|
{
|
|
currentState?.Exit();
|
|
currentState = newState;
|
|
currentState.Enter();
|
|
}
|
|
|
|
public void Update()
|
|
{
|
|
currentState?.Execute();
|
|
}
|
|
}
|