Simple dice rolling system.
You can roll D4, D6, D8, D10, D12, D20 dices.
JavaScript
===HOW TO===
1. Set up
Place "Dices will fall from here" prefab to a correct place in your scene.
Use Dice.Set(int-1, int-2, int-3, int-4, int-5, int-6); to set up how many dices of each type you want to roll.
int-1 - D4 dices, int-2 - classical D6 dices, int-3 - D8 dices, int-4 - D10 dices, int-5 - D12 dices, int-6 - D20 dices
For example:
To roll 4 classical dices use
Dice.Set (0, 4, 0, 0, 0, 0);
beforee rolling dice
To roll two D4 and six D20 use
Dice.Set (2, 0, 0, 0, 0, 6);
beforee rolling dice
2. Roll
Use
Dice.Roll();
3. Score
When all dices stops moving Dice.RollEnded will be true
To chek every dice use two arrays:
Dice.DiceTypeM[(0-100)] - string, type of dice was generated, can be "D4", "D6", "D8", "D10", "D12", "D20".
Dice.DiceScore[(0-100)] - int, score
For example:
To check type and score of first generated dice check Dice.DiceTypeM[0] and Dice.DiceScore[0]
if (Dice.RollEnded==true) {Our_string_varable_for_type = Dice.DiceTypeM[0]; Our_int_varable_for_score = Dice.DiceScore[0];}
To check sum of only classical dices
if (Dice.RollEnded==true) {
for (var i:int = Dice.Limit-1; i>-1; i--)
{
if (Dice.DiceTypeM[i]=="D6") {Sum_of_classical_dices = Dice.DiceScore[i] + Sum_of_classical_dices;}
}
}
4. Clear
Use
Dice.Clear();
===USEFUL VARABLES===
Dice.RollEnded - bool, true when dices is not moving
Dice.RollSum - int, contains sum of last roll
Dice.Limit - int, maximum of dices you can roll, 100 by default, change it inside Dice script
Dice.ShowScore - bool, if true - showing score during roll
Dice.ShakeMode - bool, if true - using real-world gravity (set this on true on MOBILE DEVISES ONLY)