public override void TakeDamage(int amount)
        {
            if (_vulnerable)
            {
                Health.DecreaseHealth(amount);
            }

            if (Health.IsDead)
            {
                if (_lives > 0)
                {
                    _lives--;
                    Debug.Log("Player died. " + _lives + " lives left!");

                    // Instead of destroying, disable GameObject and
                    // tell PlayerSpawner to reactivate it
                    gameObject.SetActive(false);
                    _respawner.ReSpawnPlayer();
                }
                else
                {
                    Debug.Log("Out of lives! Game over!");

                    // Let PlayerSpawner script handle final GameObject destruction.
                    _respawner.GameOver();
                }
            }
        }
 public void TakeDamage(int amount)
 {
     //Debug.Log("TakeDamage:" + amount);
     Health.DecreaseHealth(amount);
     //Debug.Log(name + " " + Health.CurrentHealth.ToString());
     Die();
 }
 public void TakeDamage(int amount)
 {
     Health.DecreaseHealth(amount);
     if (Health.IsDead)
     {
         Die();
     }
 }
        public override void TakeDamage(int amount)
        {
            Health.DecreaseHealth(amount);

            // Update the interface text.
            LevelController.Current.UpdateHealth(Health.CurrentHealth);

            if (Health.IsDead)
            {
                Die();
            }
        }
Beispiel #5
0
        /// <summary>
        /// Inflicts damage to the space ship.
        /// </summary>
        /// <param name="amount">the amount of damage</param>
        public virtual void TakeDamage(int amount)
        {
            // If the space ship isn't invulnerable, it takes damage
            if (!Invulnerable)
            {
                // Decreases the current health
                Health.DecreaseHealth(amount);

                // Prints debug info
                //Debug.Log(name + ": " + amount + " damage! HP: "
                //    + Health.CurrentHealth);

                // Kills the space ship if its HP reaches the minimum value
                if (Health.IsDead)
                {
                    Die();
                }
            }
        }
        //When Spaceships collide with something they take famage
        void OnTriggerEnter2D(Collider2D collision)
        {
            // if Collision with game object = true: take damage
            if (collision.gameObject)
            {
                //Getting damage from Projectile doesn't work and don't know was it requirements
                _damage = GetComponent <Projectile>(); //Damage that is done to the ships
                _health = GetComponent <Health>();     //Current Healt of the ship that is collided

                //Debuggin the value of the _damage
                Debug.Log(_damage);

                //check if _health is null or not
                if (_health != null)
                {
                    //Decreases health amount of damage
                    _health.DecreaseHealth(30); // Change the value to _damage variable when you get things to work.
                }

                //Destroy projectiles when you hit the enemyship and player if collides with enemy
                //Destroy(collision.gameObject);
            }
        }