- Home /
Question by
Dark_Wolfized · Jun 19, 2014 at 02:34 AM ·
collisiondestroydestroygameobject
How to destroy game object after a delay
I need to destroy a gameobject that has a sound on it which plays when you enter the collision mesh. The sound works but I cant get the gameobject to be destroyed without the sound not playing.
This is the sound code
var SoundClip:AudioClip;
var IsSound = true;
function OnTriggerEnter (o:Collider){
Debug.Log("enter quack");
if(IsSound == true){
playSound();
}
}
function playSound(){
audio.PlayOneShot(SoundClip);
}
what I need to happen is that the sound plays and then the object gets deleted so that the sound cant be played again.
Comment
Best Answer
Answer by robertbu · Jun 19, 2014 at 02:35 AM
Destory() has an optional second parameter that specifies a future time. So you can use:
Destory(gameObject, SoundClip.length);
@robertbu, could you tell me what if I what code to be executed after object was destroyed by this method? What should I do?
Your answer
