Can someone tell me the the correct way to pause a game on Android? Currently what i am doing is just to set the Time.timeScale to 0 and AudioListener.pause to true; I do it in the game scene itself(Nothing hovers above the scene when paused). Code is give for reference
void pauseGame(){
paused = true;
Time.timeScale = 0f;
pauseGui.text = "[ resume ]";
AudioListener.pause = true;
Debug.Log("paused..");
}
void resumeGame(){
paused = false;
Time.timeScale = 1f;
pauseGui.text = "[ pause ]";
AudioListener.pause = false;
Debug.Log("resumed..");
}
The problem that I face is when I pause the game, lock my screen (Android) and then unlock it, the AudioListener gets re-enabled (don’t know why).
I can use an Update() method to check and set AudioListener.pause to true if ‘paused’ boolean is true. But that will cause the background music to play for a split second.
I know that there is some-other neat and correct way to pause the game, but don’t know how. I am just starting to learn unity.
Can someone help me?