Game Development Reference
In-Depth Information
OnApplicationFocus is an event sent to all objects in the scene when the game
loses focus, typically when the game window is deactivated on desktop computers
during multitask operations. This can be a significant in-game event, especially for
multiplayer games where action and events in a shared world continue, even when
one or more of the players are not actively participating. In these cases, you may
need to pause or resume specific behaviors or fade-in or fade-out game music.
OnApplicationPause is an ambiguous event because the concept of a pause in Unity
is not clearly defined. There are, I believe, two distinct kinds of pauses, namely, an
ultimate and relative pause. The ultimate kind is where every activity and every
event in a game is totally suspended; in this state, there is no passing of time and
nothing can move forward. The relative kind, in contrast, is the most common. Here,
the game is self-conscious or aware of being in a paused state; it halts some events,
such as in-world events, but allows other events to continue such as GUI interaction
and user input, which can unpause the game. The OnApplicationPause event refers
to the first kind of pause and not the latter. This event will be called when several
conditions are met. These are considered in the next sections.
First, OnApplicationPause will only be called on the desktop if the Run In
Background option is not enabled in the Player Settings tab, under the Resolution
group, as shown in the following screenshot. This option, when disabled, will
automatically pause a desktop game whenever the window focus is lost. This
means OnApplicationPause will follow an OnApplicationFocus event.
Disabling the Run In Background option
 
Search WWH ::




Custom Search