I’m using “AudioClip” and I have a menu to pause animations. I can’t seem to pause the sound though e.g. I have a sound of a character jumping, but when I pause the sound keeps on playing. Is there like .pause I can use or? I can’t seem to find anything I can use at the reference page.
Basically I’d like the sound that can pause and to continue the sound after pause.
Sorry, I forgot to mention that I’ve used “AudioListener.pause” before. It does disables the sound but it disables the music as well(which I don’t want it to). Plus if I’m playing a laughing sound and set the pause = true, setting it back to false won’t continue the audio.
Right now, I have a music bacground and sound that can be triggered when performing an action. What I’d like to do is when I pause, the music should still be playing but I like for the sound to pause. Unpausing it should continue playing the sound.
The AudioSourcePause works but only for the musicbackground I have. I also tried attached multiple audiosource(around 10) to play around with. It sort of works but I had to create multiple condition statements just to make sure the sound doesn’t play when I don’t want it.
Previously, I defined my audio files as audio.Clip and play them using AudioPlayOneShot. So to actually use audioSource.Pause, I had redefine everything as audiosources.
Thanks again. I’ll try and think if I can find a work around this.
Thanks dude. I’ll try and see about this method. I’m not sure if I managed to solved it or not before. I think in the end I just had to make sure it play, then stops and replace it with a different audio.
You could create a script called AudioIgnoringPause.cs (or .js, whatever) and define a public array of audiosources in it. The audiosources in that array (assigned by dragging the objects with the audiosource on it into the array in the Inspector view) will then ignore the pause state whenever you pause your game.
Here is how I did it:
//AudioIgnoringPause.cs:
public AudioSource[] audioSourcesToIgnore;
void Start(){
foreach(AudioSource snd in audioSourcesToIgnore){
snd.ignoreListenerPause = true;
}
}
//PauseGameScript.cs:
void OnGUI(){ //OnGUI because I also had some clickable buttons in my pause menu
if(pause){
Time.timeScale = 0.0f;
AudioListener.pause = true;
//all the other stuff you wanna do in your pause menu
}
else{
Time.timeScale = 1.0f;
AudioListener.pause = false;
}
}
Now all the audiosources of the array audioSourcesToIgnore will still be playing while the game is paused
i know its late but in case someone is looking use the AudioSource.Pause() for pausing the audio and use the Audio.UnPause() for resuming the audio from where you have paused it…