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