Пример #1
0
    public void TakeDamage(float amount, Transform lastHit)
    {
        _lastHit = lastHit;
        if (enemyUI)
        {
            enemyUI.EnemyDamaged(amount);
        }

        if (enemyStats)
        {
            enemyStats.TakeDamage(amount);

            if (enemyStats.IsAlive() && enemyStats.GetCurrentHealth() <= 0f)
            {
                enemyStats.Dead();

                if (Random.value < enemyStats.GetDropRate())
                {
                    LootManager.instance.SpawnAbilityPickup(transform.position);
                }

                if (canDropMoney)
                {
                    DropMoney();
                }

                if (killedByPlayer)
                {
                    TransferData(lastHit);
                }
                if (lastHit == GameManager.instance.player.transform)
                {
                    GameManager.instance.player.GetComponent <PlayerXP>().AddExp(enemyStats.GetExperience());
                }

                Destroy(this.gameObject);
            }
        }
    }