Search Unity

state machine question

Discussion in 'Scripting' started by Michael_93, Sep 1, 2014.

  1. Michael_93

    Michael_93

    Joined:
    Jan 12, 2014
    Posts:
    95
    Ok so I have been looking into state machines for a while now and I have a few questions about them which I couldn't find on google.
    My purpose is to control the flow of the game (play, pause, menus, die etc) now do I even need to do a state machine to do this without getting messy code and a headache latter down the road.
    Secondly I've seen state machines that have multiple scripts so a start script, die state script, menu state script etc or would it make more sense to have one big script with multiple methods for each state?

    Now I'm trying to develop a fairly simple mobile game so I want a fast system. If you know any good tutorial sites please let me know.

    Thank you for any feedback
     
  2. Patico

    Patico

    Joined:
    May 21, 2013
    Posts:
    886
  3. Polymorphik

    Polymorphik

    Joined:
    Jul 25, 2014
    Posts:
    599
    If its simple, just use C#'s events and delegates to trigger certain things. I use this for player movement, pausing / unpausing a game etc. no need for a state controller. If you know how to use one, then awesome if not look into events and delegates its much easier and code friendly. You only really need a state machine when you care about the states of an object at any point in time and its transitional phase from one state to the other.
     
  4. Michael_93

    Michael_93

    Joined:
    Jan 12, 2014
    Posts:
    95
    patico great thanks for the tutorials I'll check them out for sure
    Polymorphik thank you for the advice but I think it requires a state machine.