Calculate the value of a multi sided die launch

I have a coroutine that launch different dice and wait for them to stop to do something. All fine here.
The dice are common rpg style dice (d4, d6, d8, d10, d12, d20) made with simple meshes (taken from the asset store).
Now, I want that do something to calculate the total value of the throw. And I really don’t know how to do it. Any suggestion?

Well, first you need some way to define the actual sides of the die. The usual way would be to define a local normal vector for each side of the die. That vector should point up or downwards when the die rests on that side. When the die comes to rest you would simply check which vector is closest to world up / down.

Which concrete asset from the store are you talking about? Was it a free asset or a paid asset?

I just quickly created two scripts that should solve your problem.

The “Die” script should be attached to your actual Die prefab. Just drag the prefab into the scene and attach the script. Now you can enter edit mode in the inspector of the Die script. This allows you to easily “pick” the face normal vectors inside the SceneView. Make sure you first center the view on your object (press “F”) then you can orbit the object with ALT+left-drag and zoom with the mouse wheel.

The normals for each face should point upwards. Dice which have parallel sides are the easiest to define since you can simply click on a face and have the right normal vector. However for the “d4” there is no “up side”. Here you would simply select the bottom face and then click “flip”. Each side definition allows you to specify the value of that side.

The Die script also has a method called “GetCurrentValue()” which does the vector check to determine which side is up and returns the value of the side that is closest to the world up vector

Keep in mind once you setup all sides of your die you want to hit “Apply” to save the changes to the prefab.

At runtime when you select the die in the editor, the inspector will show the current value of the die for debugging purposes.