DestroyOnTrigger.cs 315 B

12345678910111213
  1. using UnityEngine;
  2. // Destroy owning GameObject if any collider with a specific tag is trespassing
  3. public class DestroyOnTrigger : MonoBehaviour
  4. {
  5. public string m_Tag = "Player";
  6. void OnTriggerEnter(Collider other)
  7. {
  8. if (other.gameObject.tag == m_Tag)
  9. Destroy(gameObject);
  10. }
  11. }