Beispiel #1
0
        /// <summary>
        /// When the player takes damage from a object
        /// </summary>
        /// <param name="amt"></param>
        public void TakeDamage(float amt)
        {
            if (!readyToRespawn)
            {
                if (coolDownInvulnerability > 0)
                {
                    return;                      // cooldown not finished...
                }
                coolDownInvulnerability = 0.25f; // cooldown until we can take damage again
                repawnTime = repawnTimeSet;

                if (amt < 0)
                {
                    amt = 0;   // negative numbers are ignored
                }
                health -= amt; // health = health - amt;

                SoundEffectBoard.PlayerDamaged();

                if (health <= 0)
                {
                    lives--;
                    readyToRespawn = true;

                    foreach (MeshRenderer meshPiece in playerRespawnEffect)
                    {
                        meshPiece.enabled = false;
                    }
                    exhaustPipe.Stop();
                    stopMovementWhenRespawning.enabled = false;

                    if (lives > 0)
                    {
                        health = healthMax;
                    }
                }
                healthBar.value    = health;
                livesNotifier.text = "Lives: " + lives; // Tells player the lives they have left.

                if (lives <= 0)
                {
                    Die(); // when the player has no more health
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// When the player takes damage from a object
        /// </summary>
        /// <param name="amt"></param>
        public void TakeDamage(float amt)
        {
            if (coolDownInvulnerability > 0)
            {
                return;                      // cooldown not finished...
            }
            coolDownInvulnerability = 0.25f; // cooldown until we can take damage again

            if (amt < 0)
            {
                amt = 0;                               // negative numbers are ignored
            }
            health -= amt;                             // health = health - amt;

            healthNotifier.text = "Health: " + health; // updates health when player takes damage
            SoundEffectBoard.PlayerDamaged();

            if (health <= 0)
            {
                Die();              // when the player has no more health
            }
        }