using System.Collections; using System.Collections.Generic; using UnityEngine; public class StateMachine where T : MonoBehaviour { public State CurrentState { get; private set; } public State PreviousState { get; private set; } public void SetState(State newState) { if (CurrentState == newState) return; if (newState == null) return; if (CurrentState != null) CurrentState.OnStateExit(); PreviousState = CurrentState; CurrentState = newState; CurrentState.OnStateEnter(); } public void RevertState() { if (PreviousState != null) SetState(PreviousState); } public void Tick() { CurrentState.Tick(); } public void FixedTick() { } }