- Home /
Different music for pause menu?
Hello,
I've been attempting to achieve this all day and I can't seem to do it. In my scene, I have a player and two audio sources. One audio source is playing the music I want for the scene (level), and the other audio source is playing the song that I want to be audible in the pause menu. When the player presses the Escape Key, a pause menu pops up. Is there any way I can get one audio source to mute, and the other audio source to unmute when the player hits the escape key? Both audio sources are attached to Empty GameObjects with 2D sounds. Thank you so much for taking the time to help me out!! Thank you!
Answer by Tomer-Barkan · Nov 18, 2013 at 08:02 AM
One way would be to attach the following simple script to both audio sources:
if (Input.GetKeyDown(KeyCode.Escape)) {
audio.mute = !audio.mute;
}
And then in the inspector, set the audio source of the scene to not muted, and the audio source of the pause menu to muted. Every time you press Escape, each audio source will switch from mute to unmute.
A more robust way to do this would be whenever you are opening the pause GUI, to mute one source and unmute the other, but you didn't share enough of your scripts for me to help you with more than the general idea.
Thank you so much for your help! I'll give your script a go! Again, THAN$$anonymous$$ YOU!
This script works for the scene audio, but when the Pause Audio source starts muted, it will not "unmute." It just stays silent. Do you have any ideas why this is?
$$anonymous$$ake sure you have the same code from my answer attached to the pause audio, in the Update()
method. There's no reason it shouldn't work.
$$anonymous$$aking sure - there's only one audio source attached to each game object.
That is correct. Only one Audio Source is added. The only problem I am having is when I start the scene with the mute box checked on the audio source, it won't unmute when I press the escape key. It just stays checked and nothing plays. Is it a glitch? I don't think so... There's gotta be something wrong here.
Try some debugging:
if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Escape)) {
audio.mute = !audio.mute;
Debug.Log(gameObject.name + ": " + audio.mute);
}
Your answer
Follow this Question
Related Questions
Audio slider for multiple scenes. 2 Answers
dynamic audio measuring? 0 Answers
Audio Toggle Background Music (With Trigger ) 2 Answers
Music On/Off Switch 2 Answers