Sent to all game objects when the player gets or loses focus.
var paused: boolean; function OnGUI() { // Show a message if the game is paused. if (paused) { GUI.Label(new Rect(100, 100, 50, 30), "Game paused"); } } function OnApplicationFocus(focusStatus: boolean) { paused = focusStatus; }
using UnityEngine; using System.Collections; public class Example : MonoBehaviour { public bool paused; void OnGUI() { if (paused) GUI.Label(new Rect(100, 100, 50, 30), "Game paused"); } void OnApplicationFocus(bool focusStatus) { paused = focusStatus; } }
import UnityEngine import System.Collections public class Example(MonoBehaviour): public paused as bool def OnGUI() as void: if paused: GUI.Label(Rect(100, 100, 50, 30), 'Game paused') def OnApplicationFocus(focusStatus as bool) as void: paused = focusStatus