コード例 #1
0
    public void ApplyDamage(Vector2 position, int damage)
    {
        if (healthPoints == 0)
        {
            return;
        }
        healthPoints = Mathf.Max(0, healthPoints - damage);

        float angle = Mathf.Atan2(transform.position.y - position.y, transform.position.x - position.x);

        FX.Instance.PlayPostProcessEffect(damagePPFX, Camera.main.WorldToScreenPoint(transform.position), angle);

        if (GetComponent <PlayerSound>())
        {
            GetComponent <PlayerSound>().PlaySound();
        }


        if (OnDamage != null)
        {
            OnDamage.Invoke(position, damage);
        }

        if (healthPoints == 0)
        {
            FX.Instance.PlayPostProcessEffect(deathPPFX, Camera.main.WorldToScreenPoint(transform.position), angle);
            if (OnDeath != null)
            {
                OnDeath.Invoke();
            }
        }
    }
コード例 #2
0
 public void TakeDamage(int damageValue)
 {
     CurrentHealth -= damageValue;
     if (CurrentHealth < 0)
     {
         CurrentHealth = 0;
         onLostHealth.Invoke(this);
         onZeroHealth.Invoke();
     }
     else
     {
         onLostHealth.Invoke(this);
     }
 }
コード例 #3
0
ファイル: EnemyHealth.cs プロジェクト: Svarog00/FlowAway
    private void Death()
    {
        FindObjectOfType <AudioManager>().Play(this.ToString());
        OnZeroHealth?.Invoke(this, EventArgs.Empty);
        Count();

        if (objectPool != null)
        {
            ReturnToPool();
        }
        else
        {
            Destroy(gameObject, 0.5f);
        }
    }