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); } }
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); } }