
⭐OnApplicationFocus()
📱 Sent to all GameObjects when the application loses or gets focused 📱 Function: checks if the current application is in focus or not 📱 Called immediately after OnApplicationPause() ✅ 📱 Called when an application (unity editor window) gets or loses focus 📱 when an application goes to the background (boolean: false ), as the game application has lost focus 📱 Returns false when the play mode is exited from 📱 When an application comes to the front (boolean: true), as the game application is in focus 📱OnApplicationFocus()takes a boolean (true
orfalse
) as an argument
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CubeController : MonoBehaviour
{
// Start is called before the first frame update
void Awake()
{
Debug.Log("Awake event");
}
void OnEnable()
{
Debug.Log("OnEnable event");
}
void Start()
{
Debug.Log("Start event");
}
void OnApplicationPause(bool pauseState)
{
Debug.Log("The application is paused: " + pauseState);
}
void OnApplicationFocus(bool focusState)
{
Debug.Log("The application's focus state is: " + focusState);
}
}