IMHOTEP Framework
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Pages
DestroyOnTriggerEnter.cs
1 //======= Copyright (c) Valve Corporation, All rights reserved. ===============
2 //
3 // Purpose: Destroys this object when it enters a trigger
4 //
5 //=============================================================================
6 
7 using UnityEngine;
8 using System.Collections;
9 
10 namespace Valve.VR.InteractionSystem
11 {
12  //-------------------------------------------------------------------------
13  public class DestroyOnTriggerEnter : MonoBehaviour
14  {
15  public string tagFilter;
16 
17  private bool useTag;
18 
19  //-------------------------------------------------
20  void Start()
21  {
22  if ( !string.IsNullOrEmpty( tagFilter ) )
23  {
24  useTag = true;
25  }
26  }
27 
28 
29  //-------------------------------------------------
30  void OnTriggerEnter( Collider collider )
31  {
32  if ( !useTag || ( useTag && collider.gameObject.tag == tagFilter ) )
33  {
34  Destroy( collider.gameObject.transform.root.gameObject );
35  }
36  }
37  }
38 }