how do i destroy object on trigger with sound in unity 5.2.2?
i have the destroy script working fine, But i want a piece of audio to play as object is removed in the hierarchy in game. Here is the script i made. this is a JS
pragma strict
function OnTriggerEnter (other : Collider) { if(other.tag == "Player") { Destroy(gameObject); } }
Answer by CapitalLlama · Aug 31, 2016 at 01:57 AM
There is a function called OnDestroy() and it is called just before an object is destroyed.
function OnDestroy(){
//Play Sound here
}
Were it says //Play Sound here do i just put the name of the audio clip? or do i make a audio source script for it?
There is a component that you assign an audio clip and then tell that component to play the audio clip. Here is a example I found (I don't know js. sorry) This all will go in the same script as above.
@script RequireComponent(AudioSource)
public var otherClip: AudioClip;
// Play default sound
function OnDestroy()
{
audio.Play();
}
Your answer
Follow this Question
Related Questions
Second AudioClip won't play 0 Answers
My sound effect is not playing 0 Answers
How to make an editor extension to unity ui for switching audio clips? 0 Answers
Why won't my second Audio Source play? 0 Answers