Exemple #1
0
    private IEnumerator GameLoop()
    {
        turnNumber = 1;
        turnUI.Setup(maxTurnNumber);
        actionTimer.Setup(enemy.characterData.actionTime);
        playerHealthIndicator.SetHP(player.characterData.hp);
        enemyHealthIndicator.SetHP(enemy.characterData.hp);
        playerHealthIndicator.gameObject.SetActive(true);
        enemyHealthIndicator.gameObject.SetActive(true);
        actionTimer.gameObject.SetActive(true);
        turnUI.gameObject.SetActive(true);
        do
        {
            turnStartHintUI.SetTrigger("Play");
            turnUI.UpdateTurn(turnNumber);
            yield return(new WaitForSeconds(1f));

            isAnswerRight    = false;
            waitPlayerAnswer = true;
            int quizIndex = (int)Mathf.Repeat(turnNumber - 1, quizzes.Length);
            quizUI.Show(quizzes[quizIndex]);
            float timer = enemy.characterData.actionTime;
            while (timer > 0 && waitPlayerAnswer)
            {
                yield return(null);

                timer -= Time.deltaTime;
                actionTimer.UpdateTimer(timer);
            }
            yield return(new WaitForSeconds(1f));

            quizUI.gameObject.SetActive(false);
            if (isAnswerRight)
            {
                player.Attack(enemy);
            }
            else
            {
                enemy.Attack(player);
            }
            yield return(new WaitForSeconds(2f));

            turnNumber++;
        } while (turnNumber <= maxTurnNumber && player.characterData.hp > 0 && enemy.characterData.hp > 0);
    }