Exemplo n.º 1
0
        /// <summary>
        /// Damage is dealt to the AI.
        /// </summary>
        /// <param name="amount">Damage value</param>
        public void TakeDamage(float amount)
        {
            if (currArmour != null)
            {
                if (amount > currArmour.ArmourHealth)
                {
                    Health -= amount - currArmour.ArmourHealth;
                }

                if (currArmour.ArmourHealth > 0)
                {
                    currArmour.Damage(amount);
                }
                else
                {
                    Health -= amount;
                }
            }
            else
            {
                Health -= amount;
            }

            if (Health <= 0)
            {
                SetToDying();
            }
        }
Exemplo n.º 2
0
    private void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.layer == LayerMask.NameToLayer("Player"))
        {
            // Damage player - caused by enemy shooting
            Player.GetInstanceHealth()?.Damage(damage);

            Score.IncreaseScore(ScoreValues.playerShot);
        }
        else if (collision.gameObject.layer == LayerMask.NameToLayer("Enemy"))
        {
            Armour armour = collision.gameObject.GetComponent <Armour>();

            if (armour != null && armour.IsActive())
            {
                // Damage armour - caused by player shooting
                armour?.Damage(damage);

                Score.IncreaseScore(ScoreValues.armouredEnemyShot);
            }
            else if (collision.gameObject.CompareTag("Head"))
            {
                EnemyHead enemyHead = collision.gameObject.GetComponent <EnemyHead>();

                // Kill enemy with 1 shot
                enemyHead?.KillEnemy();

                Score.IncreaseScore(ScoreValues.enemyHeadshot);
            }
            else if (collision.gameObject.CompareTag("HeadBoss"))
            {
                BossHead enemyHead = collision.gameObject.GetComponent <BossHead>();

                // Damage enemy - caused by player shooting
                enemyHead?.DamageHead(damage);

                Score.IncreaseScore(ScoreValues.enemyHeadshot);
            }
            else
            {
                IEnemyController enemyController = collision.gameObject.GetComponent <IEnemyController>();

                // Damage enemy - caused by player shooting
                enemyController?.DamageEnemy(damage);

                Score.IncreaseScore(ScoreValues.enemyShot);
            }
        }
        else if (collision.gameObject.layer == LayerMask.NameToLayer("Cover"))
        {
            Health coverHealth = collision.gameObject.GetComponent <Health>();

            // Damage cover - caused by enemy shooting
            coverHealth?.Damage(damage);
        }

        // Destroy Bullet
        Destroy(gameObject);
    }