Search Unity

Question Can someone help me

Discussion in 'Scripting' started by Lazarkov1234, Dec 4, 2022.

  1. Lazarkov1234

    Lazarkov1234

    Joined:
    Oct 17, 2021
    Posts:
    6
    I am understanding the concept of state machines but I just can't implement! Every time I try it just doesn't work. Can anyone send me a link of a video or anything so I can finally learn to use State machine?
     
  2. Terraya

    Terraya

    Joined:
    Mar 8, 2018
    Posts:
    646
    Well, it comes down to "what state machine" you want to learn?

    Here you got a FSM:


    Also there is another SO-SM
     
    Kurt-Dekker likes this.
  3. Lazarkov1234

    Lazarkov1234

    Joined:
    Oct 17, 2021
    Posts:
    6
    tysm!
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,745
    As Terraya points out, what do you want to implement? A state machine is just a broad description of a possible tool used to solve problems. Technically almost anything with state in a computer IS a state machine.

    Here's one, it's a blinker:

    Code (csharp):
    1. private bool blink;
    2.  
    3. void Update()
    4. {
    5.   blink = !blink;
    6. }
    Done. Every update blink will turn off if it was on, and on if it was off.

    Every other state machine is simply the above but with more possible states.

    This is my position on finite state machines (FSMs):

    https://forum.unity.com/threads/state-machine-help.1080983/#post-6970016

    I'm kind of more of a "get it working first" guy.

    Ask yourself, "WHY would I use solution XYZ when I just need a variable and a switch statement?"

    All FSM solutions I have seen don't actually improve the problem space.

    Your mileage may vary.

    "I strongly suggest to make it as simple as possible. No classes, no interfaces, no needless OOP." - Zajoman on the Unity3D forums.
     
    Lazarkov1234 likes this.