예제 #1
0
    public void InflictDamage(float damage, bool isExplosionDamage, GameObject damageSource)
    {
        if (health)
        {
            var totalDamage = damage;

            // skip the crit multiplier if it's from an explosion
            if (!isExplosionDamage)
            {
                if (health.gameObject.CompareTag("Player"))
                {
                    PlayerScore player = FindObjectOfType <PlayerScore>();
                    player.DecreasePoints(3);
                }
                totalDamage *= damageMultiplier;
            }

            // potentially reduce damages if inflicted by self
            if (health.gameObject == damageSource)
            {
                if (health.gameObject.CompareTag("Player"))
                {
                    PlayerScore player = FindObjectOfType <PlayerScore>();
                    player.DecreasePoints(1);
                }
                totalDamage *= sensibilityToSelfdamage;
            }

            // apply the damages
            health.TakeDamage(totalDamage, damageSource);
        }
    }
예제 #2
0
    private void HandleDeath()
    {
        if (m_IsDead)
        {
            return;
        }

        // call OnDie action
        if (currentHealth <= 0f)
        {
            if (onDie != null)
            {
                if (gameObject.CompareTag("Enemy"))
                {
                    PlayerScore player = FindObjectOfType <PlayerScore>();
                    player.AddPoints(30);
                    //print("Enemy killed " + player.currentPoints);
                }

                if (gameObject.CompareTag("Player"))
                {
                    PlayerScore player = FindObjectOfType <PlayerScore>();
                    player.DecreasePoints(30);
                    // print("Player died" + player.currentPoints);
                    player.UpdateHighScore();
                }
                m_IsDead = true;
                onDie.Invoke();
            }
        }
    }