Ejemplo n.º 1
0
    void OnCollisionEnter2D(Collision2D collision)
    {
        //handles fall damage when the player collides with the ground at a high velocity
        if (readyToTakeFallDamage)
        {
            readyToTakeFallDamage = false;
            HandleFallDamage();
        }

        if ((collision.collider.gameObject.layer == 12 || collision.collider.gameObject.layer == 9) && canTakeDamage)         //player struck by enemy or enemy shot
        {
            if (!hasShieldActivated)
            {
                if (currentHealth > 1)
                {
                    HandleNonFatalHits();
                }
                else
                {
                    HandleFatalHits();
                }
                currentHealth = (int)Mathf.Clamp(currentHealth - 1, 0f, maxHealth);               //health cannot go below 0
                if (currentHealth <= maxHealth && healthBar.GetMaxValue() > maxHealth)
                {
                    healthBar.ChangeMaxValue(maxHealth);
                }
                healthBar.resourceValue = currentHealth;
            }
            else
            {
                //has shield activated
                shieldValue -= 1;
                AudioSource.PlayClipAtPoint(deflectingShotSound, transform.position);
                if (shieldValue <= 0)
                {
                    GameObject currentShieldSpawn = GameObject.FindGameObjectWithTag("Shield");
                    Destroy(currentShieldSpawn);
                    print("Should have destroyed the shield spawn");
                    DeactivateSuperpower();
                }
            }
            canTakeDamage = false;
            Invoke("turnOnAbilityToTakeDamage", 1.0f);
        }
    }
Ejemplo n.º 2
0
 void ActivateShield()
 {
     print("shield activated");
     if (!hasShieldActivated)
     {
         hasShieldActivated = true;
         shieldSpawn        = Instantiate(shield, transform.position, Quaternion.identity) as GameObject;
         //shieldSpawn.transform.parent = transform; //ensures that the shield always stays at the same position as the player while active
         shieldBar.resourceValue = shieldBar.GetMaxValue();
         shieldValue             = 5;
         //Invoke("DeactivateSuperpower", 5f);
     }
 }