Version: 2019.1

MonoBehaviour.OnApplicationPause(bool)

Switch to Manual

Parameters

pauseStatusTrue if the application is paused, else False.

Description

Посылается ко всем игровым объектам когда плейер на паузе.

OnApplicationPause is set to true or false. Normally, false is the value returned by the OnApplicationPause message. This means the game is running normally in the editor. If an editor window such as the Inspector is chosen the game is paused and OnApplicationPause returns true. When the game window is selected and active OnApplicationPause again returns false. True means that the game is not active.

See Resolution and Presentation in the Player Settings... to turn off Run in Background and Visible in Background.

OnApplicationPause can be used in an independent game running separately from the editor. The running game needs to be windowed and smaller than the full screen. If the game is hidden (fully or partly) by another application then OnApplicationPause will return true. When the game is changed back to current it will no longer be paused and OnApplicationPause will return to false.

OnApplicationPause can be a co-routine; to do this use the yield statement in the function. Implemented this way, it is evaluated twice during the initial frame: first as an early notification, and secondly during the normal co-routine update step.

On Android, when the on-screen keyboard is enabled, it causes a OnApplicationFocus(false) event. Additionally, if you press "Home" at the moment the keyboard is enabled, the OnApplicationFocus() event is not called, but OnApplicationPause() is called instead.

Note: MonoBehaviour.OnApplicationPause receives true or false. There is no way to call this message. Also the keyboard/mouse/etc has no way to control MonoBehaviour.OnApplicationPause. Pause means the game is running normally or has been suspended.

Note: MonoBehaviour.OnApplicationPause is called as a GameObject starts. The call is made after Awake. Each GameObject will cause this call to be made.

using UnityEngine;

public class AppPaused : MonoBehaviour { bool isPaused = false;

void OnGUI() { if (isPaused) GUI.Label(new Rect(100, 100, 50, 30), "Game paused"); }

void OnApplicationFocus(bool hasFocus) { isPaused = !hasFocus; }

void OnApplicationPause(bool pauseStatus) { isPaused = pauseStatus; } }