- Home /
Question by
WalidF · Mar 03, 2020 at 12:08 AM ·
c#androidonapplicationpauseonapplicationfocus
onApplicationPause / Focus not executing the full command | Mobile
I'm trying to pause a counter when a player exits the game on mobile.
Here's my counter:
public float countUp;
pubic bool gamePaused;
void Update()
{
if (!gamePaused)
{
countUp += Time.unscaledDeltaTime;
}
}
This is the code for when the player exits:
private void OnApplicationFocus(bool focus)
{
gamePaused = !focus;
Debug.Log("bool value: " + gamePaused);
}
private void OnApplicationPause(bool pause)
{
gamePaused = pause;
Debug.Log("bool value: " + gamePaused);
}
I tried debugging on Android, the bool value was actually changing when I exit and come back. The timer however does not stop.
I even tried setting the value of countUp to zero inside OnApplicationFocus to test it out, but that didn't work. It wouldn't even debug the value of the variable countUp.
Can anyone please explain why this isn't working?
Thanks in advance.
Comment