change to state machine

This commit is contained in:
VDH
2025-09-08 09:20:50 +07:00
parent 1d7a284aaf
commit ee8b1d6a98
20 changed files with 442 additions and 3 deletions
+35
View File
@@ -0,0 +1,35 @@
using UnityEngine;
public class PlayerStateMachine
{
PlayerState _state;
public void InitState(PlayerState state)
{
if (_state != null)
{
Debug.LogWarning("_state is already inited");
return;
}
_state = state;
}
public void ChangeState(PlayerState state)
{
if (_state == null )
{
Debug.LogError("you need to init state first ");
return;
}
if (_state == state)
{
Debug.LogWarning("Unchanged state");
}
_state.Exit();
_state = state;
_state.Enter();
}
public void UpdateState()
{
_state.Update();
}
}