- Home /
Problem with AudioListener,Problem with my theme in main menu not playing
When i pause my game with my ingame pause button i have set the AudioListener.pause = true; and the sound stops and when i press my resume button i set AudioListener.pause = false; and my game sound continues. But if i press the main menu button from my pause menu i get back to the main menu but my main menu theme doesn't start to play? What have i done wrong and what can i do to fix it?,When i press the pause button in my game i pause the whole game and i use AudioListener.pause = true; if i resume the game i set AudioListener.Pause = false; but if i go to my main menu with the button for the main menu and i use AudioListener.pause = false; my main menu music theme refuses to play? what have i done wrong?
Answer by DerDerErIst · Dec 12, 2017 at 11:03 PM
I tried to follow this, i think u have the Main Menue in the same Scene right?
So when u call ur Main Menu and u set the Audio Listener to false... its FALSE the Audio Listener is not ur Audio File. If u want play a different kind of Music/Thema/Sound in the Main menue then u need to set 2 Audio Sources so when u make Pause u stop ur Music but when u open ur Main Menue u want a different kind of Music so u have to Deactivate the Audio from the Game and Activate the Audio from the Menue
u simply can archive this with
public AudioSource gameAudio; // Set in Inspector
public AudioSource mainAudio; // Set in Inspector
// Or set them with Find Object or something this is complete up to you
public void MainAudio()
{
gameAudio.Stop();
mainAudio.Play();
}
public void GameAudio()
{
mainAudio.Stop();
gameAudio.Play();
}
now u can simple use the UnityUI Button with an Onclick Function and then u call this or u make ur own functions and fill this inside
U also can load the Prefabs from Ressources into 1 Audiosource there are some more solutions like with Find and GetComponent when u have multiple Audiofiles that u wanna play after one Sound File is finished
Well i forgot to mention that i have a separate scenes for my main menu and my level. Will that solution above still solve it?
No it wont work for 2 Scenes.
$$anonymous$$hh actually thats interesting. So you go Back to your $$anonymous$$ain scene and there is a new Audio Listener and also a New Audio Source. If u set the Audio Listener in Game Scene to false its not set in $$anonymous$$ain Scene false.
U sure u have attached a Audio Source with the audio clip to an GameObject in ur $$anonymous$$ainScene and also set Active? Check ur Camera for attached Audio Listener and if its activatet?
Check ur Audio Source if "Play on Awake" enabled, also Check if this GameObject is not to far away from the Camera (or different $$anonymous$$ind of Audio Listener attached to another GameObject) because then the Audio Listener cant hear that, example orginal Settings u only hear to a maximal distance of 500 units
I have dropped my main menu theme in the project and imported it onto the scene and put it right on the scene, and audio listener is attached to the main camera and is active, if i start the game i will hear sounds from main menu but if i enter a level and then go back to main menu it wont play the theme, i have set the theme to play on awake and loop. I could try to attache the theme to one of my buttons but don't know if that would make a difference.
Your answer
![](https://koobas.hobune.stream/wayback/20220612144452im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Illuminating a 3D object's edges OnMouseOver (script in c#)? 1 Answer
Flip over an object (smooth transition) 3 Answers