예제 #1
0
    protected void Damage(float damage, Vector2 knockBackDir, float knockBack)
    {
        if (!isHurt)
        {
            if (canBeHurt)
            {
                if (navComp.enabled)
                {
                    navComp.Stop();
                    navComp.enabled = false;
                }
                rb.AddForce(knockBackDir * knockBack, ForceMode2D.Impulse);
                ObjectPoolManager.Spawn(deathVFX, transform.position, transform.rotation);
                IAudio player = ObjectPoolManager.Spawn(audioPlayerPrefab.gameObject, transform.position, transform.rotation).GetComponent <IAudio>();
                player.SetUpAudioSource(AudioManager.instance.GetSound("BugHurt"));
                player.PlayAtRandomPitch();
                canBeHurt = false;
                isHurt    = true;
                hurtVFX.BeginFlash();
                currentHealth -= damage;
                this.knockBack = knockBack * knockBackDir;
                DamageNumber dmgVFX = ObjectPoolManager.Spawn(hurtNumber, transform.position, Quaternion.identity).GetComponent <DamageNumber>();
                if (dmgVFX != false)
                {
                    dmgVFX.Init();
                    dmgVFX.SetTextValues(damage, settings.maxHealth, knockBackDir);
                }

                if (currentHealth <= 0)
                {
                    KillEnemy();
                }
            }
        }
    }