Example #1
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.tag == triggeringTag && enabled)
        {
            if (this.tag == "Player" && other.tag == "Enemy")
            {
                scoreField.SetNumber(scoreField.GetNumber() - pointsToSub);

                if (scoreField.GetNumber() == -1)
                {
                    Destroy(this.gameObject);
                }
            }
            else
            {
                Destroy(this.gameObject);
            }

            Destroy(other.gameObject);
        }
    }
Example #2
0
 private void OnTriggerEnter2D(Collider2D other)
 {
     if (other.tag == "Player")
     {
         Debug.Log("Player get 1 Life");
         scoreField.SetNumber(scoreField.GetNumber() + 1);
         Destroy(gameObject);  // Destroy the shield itself - prevent double-use
     }
     else
     {
         Debug.Log("Life triggered by " + other.name);
     }
 }