using System; using UnityEngine; namespace State { public class StateMachine : MonoBehaviour { public event Action OnStateChange; public GameState CurrentState { get; protected set; } public void ChangeState(GameState newState) { CurrentState?.OnExit(); CurrentState = newState; CurrentState?.OnEnter(this); OnStateChange?.Invoke(CurrentState); } private void Update() { CurrentState?.Update(); } } }