Teaching Newbies since 2014

kauress

  • Home
  • Javascript ❤
    • JavaScript
    • Node.js
  • WebDev Tuts
  • screencasts
  • Resources
  • VR & AR
  • Contact
  • Github
  • Twitter
  • YouTube
  • RSS
  • C++
You are here: Home / Unity3D / Unity3D Scripting API #12: OnApplicationFocus() 📱

February 6, 2021 by: Kauress

Unity3D Scripting API #12: OnApplicationFocus() 📱

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);
    }
}
Unity3D Scripting API #11: OnApplicationPause() 📱
Unity3D Scripting API #13: OnApplicationQuit() 📱

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2021 ·Kauress