Exemplo n.º 1
0
    /// <summary>
    /// Takes the damage given it and updates slider and text
    /// </summary>
    /// <param name="amount">Amount.</param>
    public void TakeDamage(int amount)
    {
        gameObject.AddComponent <DamageNumbers>();
        DamageNumbers damageNumbers = gameObject.GetComponent <DamageNumbers> ();

        damageNumbers.prefabDamage = (GameObject)Resources.Load("Damage", typeof(GameObject));
        damageNumbers.CreateDamagePopup(amount, transform.position);

        // Set the damaged flag so the screen will flash.
        damaged = true;

        // Reduce the current health by the damage amount.
        currentHealth -= amount;

        if (currentHealth <= 0)
        {
            currentHealth = 0;
        }

        // Set the health bar's value to the current health.
        healthSlider.value = currentHealth;
        healthField.text   = "<color='yellow'>" + currentHealth + "</color><color='white'> / " + maxHealth + "</color>";

        // Play the hurt sound effect.
        //playerAudio.Play ();

        // If the player has lost all it's health and the death flag hasn't been set yet...
        if (currentHealth <= 0 && !isDead)
        {
            // ... it should die.
            Death();
        }
    }
Exemplo n.º 2
0
    /// <summary>
    /// Takes the damage given it and updates slider and text
    /// </summary>
    /// <param name="amount">Amount.</param>
    public IEnumerator TakeDamage(int amount)
    {
        DamageNumbers damageNumbers = gameObject.AddComponent <DamageNumbers>();

        damageNumbers.battleCanvas = GameObject.Find("GameBoyCanvas").GetComponent <RectTransform>();
        damageNumbers.prefabDamage = prefabDamage;
        damageNumbers.CreateDamagePopup(amount, transform.position);
        ShakeCamera();

        // Set the damaged flag so the screen will flash.
        //damaged = true;

        // Reduce the current health by the damage amount.
        losingHealthCurrent = currentHealth;
        currentHealth      -= amount;
        damaged             = true;
        damageDealt         = amount;

        while (damageDealt > 0)
        {
            yield return(null);
        }
        damaged = false;


        if (currentHealth <= 0)
        {
            currentHealth = 0;
        }

        UpdateHealth();

        // Set the health bar's value to the current health.
        //healthSlider.value = currentHealth;
        //healthField.text = "<color='yellow'>" + currentHealth + "</color><color='white'> / " + maxHealth + "</color>";

        // Play the hurt sound effect.
        //playerAudio.Play ();

        // If the player has lost all it's health and the death flag hasn't been set yet...
        if (currentHealth <= 0 && !isDead)
        {
            // ... it should die.
            Death();
        }

        underAttack = false;
    }