slimecing

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

State.cs (651B)


      1 using System.Collections.Generic;
      2 using UnityEngine;
      3 
      4 namespace Slimecing.StateMachine
      5 {
      6     public class State : MonoBehaviour, IState
      7     {
      8         [SerializeField] private List<StateChanger> changes = new List<StateChanger>();
      9         
     10         public IState CheckTransition()
     11         {
     12             foreach (var change in changes)
     13             {
     14                 if (change.ShouldChange())
     15                 {
     16                     return change.NextState;
     17                 }
     18             }
     19 
     20             return null;
     21         }
     22         public void Enter() => gameObject.SetActive(true);
     23 
     24         public void Exit() => gameObject.SetActive(false);
     25     }
     26 }