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

I need help with making a Dice

Discussion in '2D' started by IsaacTown, Mar 8, 2021.

  1. IsaacTown

    IsaacTown

    Joined:
    Mar 8, 2021
    Posts:
    3
    I'm really new to C# and I decided I wanted to make a Dice I've tried 3 Tutorials and none of them have worked can someone tell me how to make it so when you click on an Image (Or Button) in the Ui Layer it will change an Image to a number 1 - 6. I don't care about animations just want it working.
     
  2. IsaacTown

    IsaacTown

    Joined:
    Mar 8, 2021
    Posts:
    3
    Sorry I worded that wrong I want to change it to 1 of 6 images not an Imag to a number 1 - 6.
     
  3. rarac

    rarac

    Joined:
    Feb 14, 2021
    Posts:
    570
    Code (CSharp):
    1. int dice = Random.Range(1,7);
     
    knobblez likes this.
  4. knobblez

    knobblez

    Joined:
    Nov 26, 2017
    Posts:
    223
    Could use what rarac said with a switch statement:

    Code (CSharp):
    1.  
    2.  
    3. int dice = Random.Range(1,7);
    4.  
    5. switch(dice)
    6. {
    7.  
    8.      case 1:
    9.      {
    10.           //swap image to 1
    11.           break;
    12.      }
    13.  
    14.      case 2:
    15.      {
    16.           //swap image to 2
    17.           break;
    18.      }
    19. }
    20.