- Home /
 
audio.Play not working
I do not know why this is not working. can you tell me what I am doing wrong? thanks here is my code:
var CoinSound : AudioClip;
function OnTriggerEnter(other : Collider) {
 if( other.tag == "Player") {
 
     Destroy(gameObject);
     
     audio.clip = CoinSound;
     audio.Play();
 
 }
 
               }
I was told this would work but it did not
Well I see what i did. it do not give a clip time to play. so how would i fix that(to play the clip Even though the coin is gone)
Answer by AlucardJay · Feb 19, 2013 at 03:32 AM
play your sound
wait for the sound to finish playing
then destroy the object
yield WaitForSeconds( CoinSound.length );
or... use PlayClipAtPoint or PlayOneShot
 audio.PlayOneShot( CoinSound );
 
               Remember to destroy only after everything else is done =]
http://docs.unity3d.com/Documentation/ScriptReference/AudioSource.PlayOneShot.html
http://docs.unity3d.com/Documentation/ScriptReference/AudioSource.PlayClipAtPoint.html
http://docs.unity3d.com/Documentation/ScriptReference/WaitForSeconds.html
http://docs.unity3d.com/Documentation/ScriptReference/AudioClip-length.html
Your answer
 
             Follow this Question
Related Questions
video texture plays too fast when adding audio 2 Answers
Background Music 2 Answers
Play Oneshot Audio On Touch 0 Answers
Audio.Play() not showing up 1 Answer
Problem with streaming audio and play in trigger area 0 Answers