private IEnumerator RollAction(bool firstRoll, string type) { while (pause) { yield return(null); } if (firstRoll) { StartCoroutine(boardUI.HideTurnTitle(type == "player")); if (type == "player") { StartCoroutine(boardUI.ShowButtons(playerList[currentPlayer].GetCharacter().color)); } yield return(new WaitForSeconds(0.5f)); } else { int diceToDraw = 0; List <string> colorList = new List <string>(); foreach (Dice dice in dices) { if (dice.GetFaceIndex() != 1) { diceToDraw++; colorTrashBin.Add(dice.GetColor()); StartCoroutine(dice.Shrink()); } else if (!firstRoll) { colorList.Add(dice.GetColor()); } } if (diceToDraw > 0) { if (diceToDraw > colorPool.Count) { Dictionary <string, int> colorCount = new Dictionary <string, int>(); foreach (string color in colorList) { if (colorCount.ContainsKey(color)) { colorCount[color]++; } else { colorCount.Add(color, 1); } } boardUI.ResetMiniDice(colorCount); } yield return(new WaitForSeconds(0.5f)); } } foreach (Dice dice in dices) { if (dice.GetFaceIndex() != 1 || firstRoll) { if (colorPool.Count == 0) { colorPool.AddRange(colorTrashBin); colorTrashBin.Clear(); } int index = Random.Range(0, colorPool.Count); dice.SetColor(colorPool[index]); StartCoroutine(boardUI.MiniDiceShrink(colorPool[index])); colorPool.RemoveAt(index); } } Debug.LogFormat(this, "Color pool[{0}] : {1}", colorPool.Count, string.Join(", ", colorPool.ToArray())); while (pause) { yield return(null); } boardSoundsEffect.audioSource.PlayOneShot(boardSoundsEffect.dice); foreach (Dice dice in dices) { bool grow = firstRoll ? true : dice.GetFaceIndex() != 1; StartCoroutine(dice.Roll(grow, type)); playerList[currentPlayer].GetCharacter().gameStat.AddDiceFace(dice.GetFaceIndex()); } yield return(new WaitForSeconds(0.8f)); while (pause) { yield return(null); } List <Dice> clawList = new List <Dice>(); foreach (Dice dice in dices) { if (dice.GetFaceIndex() == 2) { //dice.animator.SetTrigger("highlight"); if (playerList[currentPlayer].GetLife() > 0) { StartCoroutine(boardUI.LoseLife(1)); } playerList[currentPlayer].SetLife(playerList[currentPlayer].GetLife() - 1); clawList.Add(dice); boardSoundsEffect.audioSource.PlayOneShot(boardSoundsEffect.negative); StartCoroutine(dice.Highlight()); yield return(new WaitForSeconds(0.2f)); } } if (clawList.Count > 0) { yield return(new WaitForSeconds(0.2f)); foreach (Dice dice in clawList) { StartCoroutine(dice.Lowlight()); } yield return(new WaitForSeconds(0.3f)); } while (pause) { yield return(null); } if (playerList[currentPlayer].GetLife() <= 0) { StartCoroutine(TurnOver()); } else { List <Dice> bubbleList = new List <Dice>(); foreach (Dice dice in dices) { Coroutine gainTurnScore = null; if (dice.GetFaceIndex() == 0) { //dice.animator.SetTrigger("highlight"); bubbleList.Add(dice); boardSoundsEffect.audioSource.PlayOneShot(boardSoundsEffect.positive); StartCoroutine(dice.Highlight()); if (gainTurnScore != null) { StopCoroutine(gainTurnScore); } gainTurnScore = StartCoroutine(playerList[currentPlayer].GainTurnScore(1)); yield return(new WaitForSeconds(0.2f)); } } if (bubbleList.Count > 0) { yield return(new WaitForSeconds(0.2f)); foreach (Dice dice in bubbleList) { StartCoroutine(dice.Lowlight()); } yield return(new WaitForSeconds(0.3f)); } while (pause) { yield return(null); } if (type == "player") { canPlay = true; } else { yield return(new WaitForSeconds(0.2f)); if (playerList[currentPlayer].GetScore() + playerList[currentPlayer].GetTurnScore() >= 13) { StopAction(true); } else if (playerList[currentPlayer].GetTurnScore() == 0 || playerList[currentPlayer].GetLife() >= 3) { ContinueAction(true); } else if (playerList[currentPlayer].GetLife() == 1) { StopAction(true); } else if (playerList[currentPlayer].GetTurnScore() < 3) { ContinueAction(true); } else if (playerList[currentPlayer].GetTurnScore() >= 2 && playerList[currentPlayer].GetTurnScore() <= 4) { if ((Random.Range(0, 2) == 0)) { ContinueAction(true); } else { StopAction(true); } } else { StopAction(true); } } } }