Please tell me how can I track the state of the game window. The task is to turn off the sound when the window is minimized or lost focus.
You can use the OnApplicationFocus function but I’m not sure if it works when the window is minimised.
Sorry for bringing up an old thread, but i am trying to figure out how to turn off sound when the game goes to sleep mode. So if you don’t touch anything the phone locks. The sound is still playing on the unlock screen. I’ve used the following to pause the game and turn off music when the user pushes the HOME button for example.
function OnApplicationFocus(focus : boolean) {
if(!focus) {
Time.timeScale = 0;
AudioListener.pause = true;
}
else {
Time.timeScale = 1;
AudioListener.pause = false;
}
}
I’ve also done the exact same thing with the OnApplicationPause() function. And that works great. But this does not work when the phone goes into sleep mode. So i guess there is something else i need to check. I haven’t found out what though yet, so if anyone knows that would be greatly appreciated.
Ok, found the issue. It seems like when the phone comes back from sleep the OnApplicationPause() function is called before the user unlocks the phone. So some kind of workaround in the individual case would be needed. I don’t know how one could find out if the user unlocked the phone or not.
If i press application button on task panel application minimized but sound not stopped.
Does someone know a good solution to find out when the user unlocked the phone?