change to state machine
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user