- Home /
Temporarily disable audio?
The title basically says it, but I'm making an FPS game and would like to know how to disable audio for a specific time, (for example, 3 seconds.) My FPS character can press the reload key (R) as many times as they want while it is reloading and the reload sound will play, so I need to find a way around this. Can anyone help with disabling audio temporarily (until the reload time passes) or some other way around this?
Side notes: - The reload function is called by pressing R - Once the reload is complete, the player can't reload again until either the bullets are less than a full clip, or they manually reload by pressing the R key.
(So basically the question is how can I play the audio only one time while it is reloading?)
Thanks in advance!
Can you provide a bit more details, and perhaps your code? From what I gathered, it seems like you have separate functions to do the reload and play the audio.
What's stopping you from having the audio be played from the same function as the reload? This way you can prevent the execution of the reload function until the reload is complete, thus no need to try and mute audio.
Well the problem is that while the player is reloading, they can keep calling the reload function (which lets them restart the reload sound over and over) until the reload is done
Yes, this is why I said prevent the execution of the reload function until reload completes. Surely you understand how to do this?
It's as simple as (pseudo-code)
if(!reloadAnimationIsPlaying)
{
reloadAnimationIsPlaying = true;
//do reload stuff
reloadAnimationIsPlaying = false;
}
Answer by jaj123 · Dec 14, 2013 at 12:55 AM
Something like this
var reloadTime : float;
var playing : boolean;
function Update () {
if (Input.GetButtonDown("Reload") && playing == false){
Reload();
}
}
function Reload() {
playing = true;
///PlaySound
yield WaitForSeconds (reloadTime);
playing = false;
}