function OnApplicationFocus (focus : boolean) : void
Description
Sent to all game objects when the player gets or loses focus.
OnApplicationFocus can be a co-routine, simply use the yield statement in the function.
var paused: boolean;
function OnGUI() {
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
class example(MonoBehaviour):
public paused as bool
def OnGUI():
if paused:
GUI.Label(Rect(100, 100, 50, 30), 'Game paused')
def OnApplicationFocus(focusStatus as bool):
paused = focusStatus