private void PlayerDamageHandler()
    {
        if (HealthBarScript.health + HealthBarScript.shieldPoints < damage)
        {
            player.GetComponent <PlayerGetsHit>().TakeDamage(HealthBarScript.health, this.gameObject.tag);
            HealthBarScript.health = 0;
        }

        else
        {
            if (PowerUpActivation.powerupEnablers[1])
            {
                if (HealthBarScript.shieldPoints >= damage)
                {
                    HealthBarScript.shieldPoints -= damage;
                    GameController.ShowTextEffect(-damage, shieldText, player.transform);
                }

                else
                {
                    HealthBarScript.health -= damage - HealthBarScript.shieldPoints;
                    GameController.ShowTextEffect(-HealthBarScript.shieldPoints, shieldText, player.transform);
                    player.GetComponent <PlayerGetsHit>().TakeDamage(damage - HealthBarScript.shieldPoints, this.gameObject.tag);
                    HealthBarScript.shieldPoints = 0;
                    PowerUpActivation.FreeCooldownBarPositions(PowerUpActivation.instances[1]);
                }
            }
            else
            {
                HealthBarScript.health -= damage;
                player.GetComponent <PlayerGetsHit>().TakeDamage(damage, this.gameObject.tag);
            }
        }
        canTrigger = false;
    }
Exemple #2
0
    void Update()
    {
        if (health <= 0)
        {
            health        = 0;
            canTakeDamage = false;
        }
        else
        {
            canTakeDamage = true;
        }

        if (health > maxHealth)
        {
            health = maxHealth;
        }

        if (PowerUpActivation.powerupEnablers[1] && shieldPoints > 0)
        {
            canBreakShield = true;
            shieldText.SetActive(true);
            shieldText.GetComponent <TextMesh>().text = "+ " + shieldPoints.ToString();
            if (shieldPoints + health >= maxHealth)
            {
                shieldBar.fillAmount = 1;
                healthBar.fillAmount = health / (maxHealth + shieldPoints);
            }
            else
            {
                healthBar.fillAmount = health / maxHealth;
                shieldBar.fillAmount = (health + shieldPoints) / maxHealth;
            }
        }
        else
        {
            healthBar.fillAmount = health / maxHealth;
            shieldBar.fillAmount = 0;
            shieldPoints         = 0;
            PowerUpActivation.powerupEnablers[1] = false;
            Destroy(PowerUpActivation.instances[1]);
            shieldText.SetActive(false);

            if (canBreakShield)
            {
                GameController.ShowPowerUpAnimation(disappearingAnimation, player.transform);
                PowerUpActivation.FreeCooldownBarPositions(PowerUpActivation.instances[1]);
                canBreakShield = false;
            }
        }
    }