public void DeactivateRoller() { if (currentState == DiceRollerState.Complete) { DestroyDice(); currentState = DiceRollerState.Inactive; } }
public void ActivateRoller() { if (currentState == DiceRollerState.Inactive) { CreateDice(); currentState = DiceRollerState.HoldingDice; } else if (currentState == DiceRollerState.Complete) { DestroyDice(); currentState = DiceRollerState.Inactive; ActivateRoller(); } }
/* * 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; }
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; }
// Start is called before the first frame update void Start() { currentState = DiceRollerState.Inactive; dice = new GameObject[numDice]; }