Get the App
SLTechnology News&Howtos  ›  Development  › 

How to get the throwing and points of Unity dice

Shulou Source: shulou.com Published: 2022-06-03 14:03:59 10月01日 Update

This article mainly introduces how to get Unity dice throw and points, the text is very detailed, with a certain reference value, interested friends must read!

Above first.

I won't say much about the construction of the scene, mainly dice.

method is as follows

First of all, we need to make our own six sides of the dice (this is the only way I can think of, but it will work anyway).

Each face is then renamed to a unique name based on the number of points on the dice.

For convenience, I use 1, 2, 3... to name it.

Finally, add a rigid body to it to make the dice more realistic.

PS: The extra GameObject is to adjust its center point and facilitate rotation.

Next, let's spin the dice!

When the left mouse button is clicked, a random value is given in X, Y and Z directions respectively.

Then add the desired rotation angle to the current position of the dice.

Here we give a timer and let it rotate for two seconds.

if (Input.GetMouseButtonDown(0)) { isdebug = true; //take XYZ random rotation value p_x = Random.Range(minrot, maxrot); p_y = Random.Range(minrot, maxrot); p_z = Random.Range(minrot, maxrot); timer = 0.0f;//timer cleared after click} if(timer

Tags: Dice name points next content method article timer image above center point value location interest rigid body scene guy buddy number data array Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Shulou Tech Info Linux Shulou Technology NVidia