I have strange behavior. When I show pause view I set Time.timeScale to zero. All gameplay logic stops after that and pause view UI is visible. This is as expected. But when I “push game to background” (click home button on Android device) and open game back someone (it is not my code, I checked many times) sets Time.timeScale to 1. Pause view UI still visible but gameplay is not pausing.
Is it correct behavior?
I tried to use following workaround:
private float _goBackgroundTimeScale = 1f;
public void OnApplicationPause(bool isPause)
{
Debug.Log("OnApplicationPause. isPause: " + isPause + ", timeScale: " + Time.timeScale + ", gobgtimescale: " + _goBackgroundTimeScale);
if(isPause)
_goBackgroundTimeScale = Time.timeScale;
else
Time.timeScale = _goBackgroundTimeScale;
}
But it doesn’t help. Time.timeScale set to 1 after OnApplicationPause function call.
I checked Time.timeScale in Update. It writes 0 when game is paused and writes 1 when game back from background work.
public override void Update()
{
Debug.Log("timescale: " + Time.timeScale);
}
How can I solve this issue? Thanks!