using UnityEngine; public interface IState { public void Enter(StateHandler excutor); public void Excute(); public void Exit(); } public class StateHandler : MonoBehaviour { public IState CurrentState { get; private set; } void Update() { if (CurrentState is null) return; CurrentState.Excute(); } public void ChangeState(IState state) { if(CurrentState != null) { CurrentState.Exit(); } CurrentState = state; CurrentState?.Enter(this); } }