- Home /
Glitchy Sound
Hi. I'm trying to get my script to play a sound when a certain variable equals 1. but when it plays it sounds really glitchy, with it trying to play the first part of the sound over and over again with a short pause inbetween.
I don't know what is causing this so i hope someone here will know what the problem is. Here is my code:
var CeaseSFX : AudioSource;
var Music : AudioSource;
function Update(){
if(ActiveRobots.numberofrobots == 1)
{
CeaseSFX.Play();
Music.mute = true;
}
else{
CeaseSFX.PlayDelayed(183);
}
}
You are playing the sound every frame, it needs to only play if it is not already playing
Answer by gregzo · Aug 04, 2013 at 09:10 PM
Chronicfall is perfectly right. Easy lazy fix is to check for isPlaying, but really you should pull this out of Update.
var CeaseSFX : AudioSource; var Music : AudioSource;
function Update()
{
if( ActiveRobots.numberofrobots == 1 && CeaseSFX.isPlaying == false )
{
CeaseSFX.Play();
Music.mute = true;
}
}
I tried what you said but the sound didn't play at all. Edit: I've got it to work but the sound loops and i don't want it to.
No I haven't ticked the loop box. because its function update it will loop it but i don't know how to stop it fromd doing so.