Esempio n. 1
0
 public void DeactivateRoller()
 {
     if (currentState == DiceRollerState.Complete)
     {
         DestroyDice();
         currentState = DiceRollerState.Inactive;
     }
 }
Esempio n. 2
0
 public void ActivateRoller()
 {
     if (currentState == DiceRollerState.Inactive)
     {
         CreateDice();
         currentState = DiceRollerState.HoldingDice;
     }
     else if (currentState == DiceRollerState.Complete)
     {
         DestroyDice();
         currentState = DiceRollerState.Inactive;
         ActivateRoller();
     }
 }
Esempio n. 3
0
    /*
     * For Following two methods:
     * https://stackoverflow.com/questions/51644503/detect-when-all-dice-have-stopped-moving
     */
    IEnumerator UpdateDiceRolling()
    {
        yield return(CheckIfDiceAreMoving());

        diceValue = 0;
        foreach (var die in dice)
        {
            if (die == null)
            {
                continue;
            }
            DiceDirection diceDrection = die.GetComponent <DiceDirection>();
            diceValue += diceDrection.getNumber();
        }

        currentState = DiceRollerState.Complete;
    }
Esempio n. 4
0
 public void TossDice()
 {
     foreach (var die in dice)
     {
         Rigidbody dieBody     = die.GetComponent <Rigidbody>();
         Vector3   force       = Vector3.Normalize(worldCamera.transform.forward) * tossForce;
         Vector3   forceOffset = Vector3.up * Random.Range(minForceOffset, maxForceOffset);
         Vector3   torque      = new Vector3(
             Random.Range(minTorque, maxTorque),
             Random.Range(minTorque, maxTorque),
             Random.Range(minTorque, maxTorque)
             );
         dieBody.AddForce(force + forceOffset);
         dieBody.AddTorque(torque);
         dieBody.useGravity = true;
     }
     currentState = DiceRollerState.DiceRolling;
 }
Esempio n. 5
0
 // Start is called before the first frame update
 void Start()
 {
     currentState = DiceRollerState.Inactive;
     dice         = new GameObject[numDice];
 }