Пример #1
0
        public void TakeDamage(float damage, bool criticalHit, Fighter attacker)
        {
            damage       = criticalHit ? damage * 2 : damage;
            HealthPoints = Mathf.Max(HealthPoints - damage, 0);

            if (_lifeBarController != null)
            {
                _lifeBarController.UpdateLifeBar();
            }

            if (CompareTag("Player"))
            {
                var healthPlayer = FindObjectOfType <HealthGlobeControl>();
                healthPlayer.StopRegen();
                healthPlayer.healthSlider.value -= (damage / maxHealthPoints);
            }

            if (_damageTextSpawner != null)
            {
                // If critical , damage * 2 else normal damage
                _damageTextSpawner.Spawn(damage, criticalHit ? DamageType.Critical : DamageType.Normal);
            }

            if (HealthPoints <= 0)
            {
                Die();
            }
            else if (_aiController != null && !_aiController.IsGoingHome)
            {
                _aiController.ConfigureTarget(attacker, damage);
            }
        }
Пример #2
0
        // instigator is the one who is causing the damage
        public void TakeDamage(int damage, GameObject instigator)
        {
            if (gameObject.tag != "Player")
            {
                print(gameObject.name + " is getting damaged" + damage + " by the " + instigator.name);
            }

            health.value = Mathf.Max(health.value - damage, 0);

            // Syncs health bar with the character's health
            onHealthChange();

            if (health.value <= 0)
            {
                // play death sound
                // we don't invoke death sound in Die()
                // bc it also gets called in restorestate()
                // and we don't want to potentially
                //  make that sound when travelling between worlds
                onDieSound.Invoke();
                Die();
                AwardEXP(instigator);
            }
            else
            {
                print("damaging " + this.gameObject.name);


                takeDamageSound.Invoke();

                // spawn a floating and fading damage display
                damageTextSpawner.Spawn(damage);
            }
        }