コード例 #1
0
 public void TakeDamage(int amount)
 {
     if (currHealth > 0)
     {
         currHealth -= amount;
         if (currHealth <= 0)
         {
             onDeath.Invoke();
             if (destroyAction != null)
             {
                 if (healthDraw != null)
                 {
                     healthDraw.ChangeHealthState(0);
                 }
                 destroyAction.StartDestroy();
             }
             else
             {
                 Destroy(gameObject);
             }
         }
         else if (healthDraw != null)
         {
             healthDraw.ChangeHealthState((float)currHealth / maxHealth);
         }
     }
 }
コード例 #2
0
 public void DestroyArrow()
 {
     if (!isDestroyed)
     {
         isDestroyed = true;
         if (destroyAction != null)
         {
             Stop();
             destroyAction.StartDestroy();
         }
         else
         {
             Destroy(gameObject);
         }
     }
 }
コード例 #3
0
    private void OnTriggerEnter2D(Collider2D coll)
    {
        if (damageLayers == (damageLayers | (1 << coll.gameObject.layer)))
        {
            HealthScript health = coll.GetComponent <HealthScript>();
            if (health != null)
            {
                health.TakeDamage(damageAmount);
            }

            if (destroyOnColl)
            {
                if (destroyAction != null)
                {
                    destroyAction.StartDestroy();
                }
                else
                {
                    Destroy(gameObject);
                }
            }
        }
    }