Esempio n. 1
0
    private void Update()
    {
        if (currentDice == null && generatedDices.Count < DICE_MAX_LIMIT)
        {
            var dicePrefab = (generatedDices.Count & 1) == 0 ? blackDicePrefab : whiteDicePrefab;
            var(location, direction) = GenerateRandom();

            dicePrefab.rollSpeed = Random.Range(1f, 5f);
            dicePrefab.moveSpeed = UnityEngine.Random.Range(3f, 6f);
            dicePrefab.direction = direction;

            currentDice = Instantiate(dicePrefab, location, Quaternion.identity);
            currentDice.RollAgain();
            generatedDices.Add(currentDice);
        }

        if (currentDice != null && diceTimer > 0f)
        {
            diceTimer -= Time.deltaTime;
        }

        if (currentDice != null && currentDice.animationFinished)
        {
            diceTimer   = DICE_REROLL;
            currentDice = null;
        }

        if (generatedDices.Count >= DICE_MAX_LIMIT)
        {
            KillGeneratedDices();
        }
    }
Esempio n. 2
0
    private void KillGeneratedDices()
    {
        foreach (var dice in generatedDices)
        {
            Destroy(dice.gameObject);
        }

        generatedDices.Clear();
        currentDice = null;
        diceTimer   = 0f;
    }