Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Game flow problem

Discussion in 'Scripting' started by antolo3, Aug 30, 2023.

  1. antolo3

    antolo3

    Joined:
    Dec 3, 2020
    Posts:
    1
    Hello, I am looking for a way to create a scene with a following flow:

    (Turn based game)

    Player turn -
    Enable player movement;
    Wait for player action;
    -if outcome is good - player and enemy have to perform certain actions.
    -if outcome is bad - do nothing and swap to enemy turn.

    Enemy turn is a mirror of the player's turn.

    After "hp" of player or enemy is 0, win/lose screen with an option to return to main menu/restart the game.

    What is the best way to create such a scene? I'm fairly new to scripting and couldn't find a good tutorial that covers this subject. Thanks :)
     
  2. ijmmai

    ijmmai

    Joined:
    Jun 9, 2023
    Posts:
    188
    The best way is to find a tutorial of a comabt turn based game, there are plenty online. Follow that one even it it doesn't exactly do what you want. Once it is all working (prepare to make some mistakes), start adjusting it to meet your own requirements.
     
    Yoreki likes this.
  3. AngryProgrammer

    AngryProgrammer

    Joined:
    Jun 4, 2019
    Posts:
    435
    You need a GameManager script in a singleton model so you can call game flow functions from any place.
    Code (CSharp):
    1. // Easy like that
    2. GameManager.Instance.EndTurn();
    Don't try to bite too much at one time. Start by making a simple sequence diagram (UML). Pen and paper, comfy chair, and coffee... Best designing model. If you can't simply describe what you want to do on paper, you will waste a lot of time coding and fixing a poor model.
     
    Last edited: Aug 30, 2023
    antolo3 likes this.
  4. Stardog

    Stardog

    Joined:
    Jun 28, 2010
    Posts:
    1,886
    You basically need a list of functions that you can step through, so look up delegates, callbacks and loops. A state machine can also handle a similar concept.