function Update () {
if (!gamemusicmanager.musicon)
{
AudioListener.pause = true;
}
else
{
AudioListener.pause = false;
}
}
the code works fine when i play game. But, when i press "Home" button to do something else, and later switch back to the game, the music continues to play for some seconds (when the game screen hasn't appear yet) and then acts normal just like when i turn it off.
I guess the AudioListener is loaded before the scene?
This seems pretty annoying. How can i stop that?
Thanks
PS: Script attached to the main camera . I guess i must replace update with something else?
use OnEnable() instead of Start() that will get called ever time your object is activated, loaded, or if the script it self is set to enabled after being set to disabled. If you don't want your audio listener to be on as soon as it loads in then you can disabled it in the scene and then enable it at runtime once the scene has loaded. Unity will spit out a few warnings saying there must be 1 audio listener but this is harmless.
I am not sure how it works on an Android ... Sorry.
– efgeuse OnEnable() instead of Start() that will get called ever time your object is activated, loaded, or if the script it self is set to enabled after being set to disabled. If you don't want your audio listener to be on as soon as it loads in then you can disabled it in the scene and then enable it at runtime once the scene has loaded. Unity will spit out a few warnings saying there must be 1 audio listener but this is harmless.
– Antony-Blackett