slimecing

a fighting game featuring slimes and swords
Log | Files | Refs | README

StateMachineComponent.cs (774B)


      1 using UnityEngine;
      2 
      3 namespace Slimecing.StateMachine
      4 {
      5     public class StateMachineComponent : MonoBehaviour
      6     {
      7         [SerializeField] private State startingState;
      8         [SerializeField] private GameObject stateMachineTarget;
      9 
     10         private StateMachine _stateMachine;
     11 
     12         public StateMachine StateMachine
     13         {
     14             get
     15             {
     16                 if (_stateMachine != null)
     17                 {
     18                     return _stateMachine;
     19                 }
     20                 
     21                 _stateMachine = new StateMachine(startingState);
     22                 return _stateMachine;
     23             }
     24         }
     25 
     26         private void Update() => StateMachine.Tick();
     27 
     28         public void ChangeState(State state) => StateMachine.ChangeState(state);
     29     }
     30 }