title: Need help understanding State Machines (C#/Unity)
body: <p>I'm struggling with this for a couple of weeks and need help with understanding and building a state machine for my game.</p>
  <p>What I need is something like this:</p>
  <p><img src="https://i.stack.imgur.com/vRKtw.png" alt="State Machine Diagram" /></p>
  <p>Basically, FSM class is just for changing states:</p>
  <pre><code>public class FSM: MonoBehaviour
  
  public StateHandler currentState { get; private set; }
  
  private void Start()
  {
      currentState.OnEnterState();
  }
  
  public void ChangeState(StateHandler newState)
  {
      currentState.OnExitState();
      currentState = newState;
      currentState.OnEnterState();
  }
  </code></pre>
  <p>State class is something like this:</p>
  <pre><code>public class StateHandler : FSM
  public virtual void OnEnterState()
  {
  
  }
  
  public virtual void OnExitState()
  {
  
  }
  
  public virtual void StateLogicUpdate()
  {
  
  }
  
  public virtual void StatePhysicsUpdate()
  {
  
  }
  
  void Update()
  {
      StateLogicUpdate();
  }
  
  void FixedUpdate()
  {
      StatePhysicsUpdate();
  }
  </code></pre>
  <p>State Attack class or any other states are the same as State class but with override methods and actual code and no update methods.</p>
  <p>I have several questions that I don't understand yet:</p>
  <ol>
  <li>How do I store states? To change them I need to get them from somewhere and putting them all on my gameobject would make them work all at once.</li>
  <li>Is this thing even going to work that way?)</li>
  <li>What's the best way to store enemy data I need to get access to while running enemy behaviour states? Just another monobehaviour script on enemy gameObject?</li>
  </ol>
  <p>And if you don't mind, answer like I'm very stupid. :) Thanks a lot!</p>