IMHOTEP Framework
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Pages
Unparent.cs
1 //======= Copyright (c) Valve Corporation, All rights reserved. ===============
2 //
3 // Purpose: Unparents an object and keeps track of the old parent
4 //
5 //=============================================================================
6 
7 using UnityEngine;
8 using System.Collections;
9 
10 namespace Valve.VR.InteractionSystem
11 {
12  //-------------------------------------------------------------------------
13  public class Unparent : MonoBehaviour
14  {
15  Transform oldParent;
16 
17  //-------------------------------------------------
18  void Start()
19  {
20  oldParent = transform.parent;
21  transform.parent = null;
22  gameObject.name = oldParent.gameObject.name + "." + gameObject.name;
23  }
24 
25 
26  //-------------------------------------------------
27  void Update()
28  {
29  if ( oldParent == null )
30  Object.Destroy( gameObject );
31  }
32 
33 
34  //-------------------------------------------------
35  public Transform GetOldParent()
36  {
37  return oldParent;
38  }
39  }
40 }