Skip to main content
Unity3D

Unity3D Scripting API #12: OnApplicationFocus() 📱

By February 6, 2021February 14th, 2021No Comments
Unity3D Scripting API
https://www.youtube.com/watch?v=lHWx3nggb-U&feature=youtu.be
OnApplicationFocus()

⭐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 or false) 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);
    }
}

Leave a Reply