Example #1
0
    //Collision
    private void OnTriggerEnter2D(Collider2D collider)
    {
        if (collider.tag == "Bullet")
        {
            health--;

            if (health <= 0 && !isDead)
            {
                isDead = true;
                if (OnDeath != null)
                {
                    OnDeath();
                }
                Debug.Log("Death1");
                soundMod.PlayModClipLate(deathSound);
                Destroy(gameObject);
                Debug.Log("Death2");
            }
            else
            {
                StartCoroutine(PlayHitAnimation());
                soundMod.PlayModClipLate(hitSound);
            }
        }
    }
Example #2
0
 void OnTriggerEnter2D(Collider2D other)
 {
     if (other.CompareTag("Bullet"))
     {
         if (playHitAnimation == null)
         {
             health--;
             healthBar.value = health;
             if (health <= 0)
             {
                 if (OnDeath != null)
                 {
                     OnDeath();
                 }
                 soundMod.PlayModClipLate(deathSound);
                 gameObject.SetActive(false);
             }
             else
             {
                 StartCoroutine(playHitAnimation = PlayHitAnimation());
                 soundMod.PlayModClip(hitSound);
             }
         }
     }
 }