campfire/Assets/SteamVR/InteractionSystem/Core/Scripts/SoundDeparent.cs
2020-04-29 20:40:05 +03:00

39 lines
949 B
C#

//======= Copyright (c) Valve Corporation, All rights reserved. ===============
//
// Purpose: Unparents this object and optionally destroys it after the sound
// has played
//
//=============================================================================
using UnityEngine;
using System.Collections;
namespace Valve.VR.InteractionSystem
{
//-------------------------------------------------------------------------
public class SoundDeparent : MonoBehaviour
{
public bool destroyAfterPlayOnce = true;
private AudioSource thisAudioSource;
//-------------------------------------------------
void Awake()
{
thisAudioSource = GetComponent<AudioSource>();
}
//-------------------------------------------------
void Start()
{
// move the sound object out from under the parent
gameObject.transform.parent = null;
if ( destroyAfterPlayOnce )
Destroy( gameObject, thisAudioSource.clip.length );
}
}
}