OnApplicationFocus() Function in Unity

Notes:

OnApplicationFocus() Function in Unity:

4. Immediately Game Application gets focus

OnApplicationFocus method:
- is called immediately after OnApplicationPause
- is also called whenever game application gets focus and gets defocus

- Whenever a game application comes to foreground it receives True value, which indicates game application has focus.
- Whenever a game application goes to background it receives False value, which indicates game application has defocus.

- is best to check whether game application is currently in focus or not

- is also called whenever game window gets focus and gets defocus
- is also called when user stops play mode in the editor

Example Code:

void OnApplicationFocus(bool isApplicationHasFocus)
{
Debug.Log ("isApplicationHasFocus " + isApplicationHasFocus);
}