예제 #1
0
    public void Damage(int amount, bool penetrateInvincibility = false)
    {
        if ((!penetrateInvincibility && (invuln || CannotHurt)))
        {
            return;
        }

        CurrentHP -= amount;
        MyGlobal.PlayGlobalSound(hurtNoise);
        Flash flashComp = this.GetComponent <Flash>();

        if (flashComp != null)
        {
            flashComp.FlashOnce();
        }
        if (CurrentHP <= 0)
        {
            if (!dead)
            {
                dead = true;
                if (deathEvent != null)
                {
                    deathEvent.Raise();
                }

                if (onDeathDelegate == null)
                {
                    Instantiate(explosionPrefab, GetComponent <Transform>().position, Quaternion.identity);
                    Destroy(this.gameObject);
                }
                else
                {
                    Instantiate(explosionPrefab, GetComponent <Transform>().position, Quaternion.identity);
                    onDeathDelegate();
                }
            }
            // m_AudioSource.PlayOneShot(deathNoise);
            ///this.GetComponent<DestroyOnTimer>().StartTimer();
        }
        else
        {
            invuln        = true;
            curInvulnTime = InvulnTime;
            if (onHurtDelegate != null)
            {
                onHurtDelegate();
            }
        }
    }