Assignment for RMIT Mixed Reality in 2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
950 B

  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. using UnityEngine;
  8. using System.Collections;
  9. namespace Valve.VR.InteractionSystem
  10. {
  11. //-------------------------------------------------------------------------
  12. public class SoundDeparent : MonoBehaviour
  13. {
  14. public bool destroyAfterPlayOnce = true;
  15. private AudioSource thisAudioSource;
  16. //-------------------------------------------------
  17. void Awake()
  18. {
  19. thisAudioSource = GetComponent<AudioSource>();
  20. }
  21. //-------------------------------------------------
  22. void Start()
  23. {
  24. // move the sound object out from under the parent
  25. gameObject.transform.parent = null;
  26. if ( destroyAfterPlayOnce )
  27. Destroy( gameObject, thisAudioSource.clip.length );
  28. }
  29. }
  30. }