Search Unity

Cant figure this oit

Discussion in 'Getting Started' started by KikiIsKawaii, Aug 17, 2023.

  1. KikiIsKawaii

    KikiIsKawaii

    Joined:
    Apr 10, 2023
    Posts:
    1
    How can i let my game randomly give out roles to players in the game.
     
  2. AngryProgrammer

    AngryProgrammer

    Joined:
    Jun 4, 2019
    Posts:
    490
    https://docs.unity3d.com/ScriptReference/Random.Range.html

    Code (CSharp):
    1. int diceRoll = Random.Range(1, 7); // can roll 1, 2, 3, 4, 5, 6 (NOT 7)
    2. // make simple if or switch
    3. if(diceRoll == 1) {
    4.     // he will be mage
    5.     }
    6. else if(diceRoll == 2) {
    7.     // he will be warrior
    8.     }
    9.  
    10. // etc.