IMHOTEP Framework
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Pages
SoundDeparent.cs
1 //======= Copyright (c) Valve Corporation, All rights reserved. ===============
2 //
3 // Purpose: Unparents this object and optionally destroys it after the sound
4 // has played
5 //
6 //=============================================================================
7 
8 using UnityEngine;
9 using System.Collections;
10 
11 namespace Valve.VR.InteractionSystem
12 {
13  //-------------------------------------------------------------------------
14  public class SoundDeparent : MonoBehaviour
15  {
16  public bool destroyAfterPlayOnce = true;
17  private AudioSource thisAudioSource;
18 
19 
20  //-------------------------------------------------
21  void Awake()
22  {
23  thisAudioSource = GetComponent<AudioSource>();
24 
25  }
26 
27 
28  //-------------------------------------------------
29  void Start()
30  {
31  // move the sound object out from under the parent
32  gameObject.transform.parent = null;
33 
34  if ( destroyAfterPlayOnce )
35  Destroy( gameObject, thisAudioSource.clip.length );
36  }
37  }
38 }