DestroyOnTrigger.cs 434 B

123456789101112131415161718
  1. using UnityEngine;
  2. namespace Unity.AI.Navigation.Samples
  3. {
  4. /// <summary>
  5. /// Destroy owning GameObject if any collider with a specific tag is trespassing
  6. /// </summary>
  7. public class DestroyOnTrigger : MonoBehaviour
  8. {
  9. public string m_Tag = "Player";
  10. void OnTriggerEnter(Collider other)
  11. {
  12. if (other.gameObject.tag == m_Tag)
  13. Destroy(gameObject);
  14. }
  15. }
  16. }