Beispiel #1
0
 /// <summary>
 /// Subtract the damage dealt from the player's total health and update the health bar.
 /// Pushes the player back in the direction he was hit from, gives invincability frames.
 /// </summary>
 /// <param name="damage">Damage Taken.</param>
 /// <param name="dirHit">Direction player was hit from.</param>
 public void TakeDamage(int damage, Vector2 dirHit)
 {
     if (falling)
     {
         return;
     }
     if (damageCollider.enabled)
     {
         if (health > 0)
         {
             health -= damage;
             if (health < 0)
             {
                 health = 0;
             }
             damageCollider.enabled = false;
             ph.ShowHealth(health);
             pc.DisablePlayer();
             an.SetTrigger("Hurt");
             healingFX.SetActive(false);
             rb.AddForce(dirHit.normalized * pushBackForce);
         }
         else if (health <= 0 && !isDead)                                      //only die if you already had just a "sliver of health" left
         //YOU DIED!!!!
         {
             damageCollider.enabled = false;
             pc.DisablePlayer();
             an.SetTrigger("Death");
             rb.isKinematic = true;
         }
     }
 }