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);
	}
}

Replace !sound.IsPlaying with !audio.isPlaying

–

I tried, nothing change

–

2 Answers

2

Have you tried unchecking the loop on the sound?

No, it's unchecked. :( Mebay it's because it is in an Update function... But I'm not sure...

–

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.

nah.. you are right bro, but it still doesn't work

–

I edited the answer

–

Thanks, it worked!

–