How can i make an easy "DICE" in C#?

Basically i want to create a dice, where you click a button, it will then change a number to 1-6.

this is what i have:

public float diceNumber (This number will be 1-6);

The above is for the number displayed.

GUI.Label (new Rect (Screen.width - 252,510,250,110), diceNumber + " Was rolled" , "box");

and this is for the button.

Can anybody help?

Thanks in advance!

Declare diceNumber as an int. Then you can use Random.Range(1,7) doc here to have a random number.

But you didn’t post any code related to the button. Is it what bothers you ?

This code is C#

int i = Random.Range(1,7);

The second parameter of the Range won’t appear (this is from 1 to 6)


In case you need the solution with the button:

private int diceNumber;
if(GUILayout.Button("Roll dice!")) diceNumber  = Random.Range(1,7);
//used a layout here but you can place button wherever you need it.