- Home /
Why sound doesn't stop?
I have the following script, that gets triggered by an othe script. I want it to play a sound only once, but it keeps playing the sound over and over. What shoul I do?
 var trig : boolean;
 var sound : AudioClip;
 
 function Update () 
 {
     if(trig && !sound.IsPlaying)
     {
         audio.PlayOneShot(sound);
     }
 }    
Answer by fafase · Oct 27, 2012 at 04:45 PM
 audio.isPlaying;
Variables in Unity often starts with lowercase when functions use uppercase.
 var trig : boolean;
 var sound : AudioClip;
 
 function Update () 
 {
     if(trig && !audio.isPlaying)
     {
        audio.PlayOneShot(sound);
        trig = false;
     }
 }
  
Now it won't repeat. You need to reset trig somewhere to get it playing later again.
Answer by Phoskryfes · Oct 27, 2012 at 08:05 AM
Have you tried unchecking the loop on the sound?
No, it's unchecked. :( $$anonymous$$ebay it's because it is in an Update function... But I'm not sure...
Your answer
 
 
             Follow this Question
Related Questions
Playing Music Problem. 2 Answers
Make a command run only once 1 Answer
Unity audio solution 1 Answer
How I can prevent music from stopping after changing a scene? 3 Answers
Music On/Off Switch 2 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                