/// <summary> /// Update is called once per frame /// </summary> void Update() { if (rolling) { // there are dice rolling so increment rolling time rollTime += Time.deltaTime; // check rollTime against rollSpeed to determine if a die should be activated ( if one available in the rolling queue ) DetermineRollQueueValues(); // what were the values of each die after rolling? if (rollQueue.Count > 0 && rollTime > rollSpeed) { // get die from rolling queue RollingDie rDie = (RollingDie)rollQueue[0]; GameObject die = rDie.gameObject; // activate the gameObject die.SetActive(true); // apply the force impuls die.GetComponent <Rigidbody>().AddForce((Vector3)rDie.force, ForceMode.Impulse); // apply a random torque die.GetComponent <Rigidbody>().AddTorque(new Vector3(-50 * Random.value * die.transform.localScale.magnitude, -50 * Random.value * die.transform.localScale.magnitude, -50 * Random.value * die.transform.localScale.magnitude), ForceMode.Impulse); // add die to rollingDice rollingDice.Add(rDie); // remove the die from the queue rollQueue.RemoveAt(0); // reset rollTime so we can check when the next die has to be rolled rollTime = 0; } else if (rollQueue.Count == 0) { // roll queue is empty so if no dice are rolling we can set the rolling attribute to false if (!IsRolling()) { rolling = false; if (allDice.Count > 0) { DiceCup.StopRolling(); } } } } }