Exemple #1
0
    public void TakeDamage(CharacterCard characterCardDoingDamage)
    {
        // Do damage to this character's health equal to characterCardDoingDamage power stat.
        this.stats.health -= characterCardDoingDamage.stats.power;
        if (this.stats.health < 0f)
        {
            this.stats.health = 0f;
        }                                                        // Clamp health to greater than zero for safety?

        // Update stats text
        this.UpdateCardStatsTexts();

        // Check if damage has resulted in health been zero (AKA killed)
        if (this.stats.health == 0f)
        {
            Debug.Log(characterCardDoingDamage.cardName + " defeated " + this.cardName);

            // Set defeated characters card color tint to gray.
            this.SetCardColor(Color.gray);
            this.StopAllCoroutines();

            // Reset the winner character color tint back to white.
            characterCardDoingDamage.SetCardColor(Color.white);
            characterCardDoingDamage.StopAllCoroutines();

            // Get gameManager to show the battle winner text.
            this.gameManager.EndBattle(characterCardDoingDamage.cardName + " defeated " + this.cardName);
        }
        else
        {
            Debug.Log(characterCardDoingDamage.cardName + " did " + characterCardDoingDamage.stats.power + " damage to " + this.cardName);

            // Start the damage color fading coroutine.
            StartCoroutine(this.DamageColorCharacter(Color.red));
        }
    }