StateMachine.cs (670B)
1 using UnityEngine; 2 3 namespace Slimecing.StateMachine 4 { 5 public class StateMachine 6 { 7 public StateMachine(IState startingState) => ChangeState(startingState); 8 9 public IState CurrState { get; private set; } 10 11 private GameObject _stateMachineTarget; 12 13 public void ChangeState(IState state) 14 { 15 CurrState?.Exit(); 16 17 CurrState = state; 18 19 CurrState?.Enter(); 20 } 21 22 public void Tick() 23 { 24 IState nextState = CurrState.CheckTransition(); 25 26 if (nextState != null) 27 { 28 ChangeState(nextState); 29 } 30 } 31 } 32 }