示例#1
0
    //IEnum for attacking
    IEnumerator Attack()
    {
        //Play the sound!
        srce.PlayOneShot(attackClip);

        //Make sure we don't attack twice
        state = GameState.TURN;

        //Check if the enemy is deaed
        bool isDead = enemyUnit.TakeDamage(playerUnit.damage);

        //Update the ui
        enemyHUD.UpdateHealthBar(enemyUnit.currentHealth);
        //Update dialogue text
        dialogueText.text = ($"You attacked {enemyUnit.unitName}!");

        //Wait for 2 secs
        yield return(new WaitForSeconds(2f));

        //Check if the enemy is dead
        if (isDead)
        {
            //If it is, you won
            state = GameState.WON;
            EndBattle();
        }
        else
        {
            //If not, continue on to enemy's turn
            state = GameState.ENEMYTURN;
            StartCoroutine(EnemyTurn());
        }
    }
示例#2
0
    //IEnum for healing
    IEnumerator Heal()
    {
        //Make sure we don't attack/heal twice
        state = GameState.TURN;

        //Use heal method in Unit script
        playerUnit.Heal(playerUnit.healAmount);

        //Update the UI
        playerHUD.UpdateHealthBar(playerUnit.currentHealth);

        //Update the dialogue text
        dialogueText.text = playerUnit.regenMessage;

        //Wait for 2 seconds
        yield return(new WaitForSeconds(2f));

        //Update the state
        state = GameState.ENEMYTURN;
        //Enemy's turn!
        StartCoroutine(EnemyTurn());
    }