- Home /
Detect when user minimizes application
Hey all, I was just trying to figure out how we can detect when a user has minimized the application (say, via alt+tab).
Here's what I'm trying to do. When the user minimizes the game, I'd like it to automatically pull up the escape menu I've created. I don't want the game to pause, I just want the escape menu to open. Is there a certain command that determines when the user has taken focus off of the game?
btw - This can be answered for Javascript or C#, either or both would be awesome!
Thanks,
There is no function to deter$$anonymous$$e this, since that's strictly a Windows problem (Something similar exists on $$anonymous$$ac, but it's a little different, and you can never "$$anonymous$$imize" a webplayer game). You would need to write a C++ plugin (Which requires Unity Pro) in order to detect when the application window has lost focus (either through alt+tab or some other means).
It's not a web-player game, it's a stand-alone application. Unity has a built in function that when focus is taken off the game it automatically pauses it or leaves it running if I wish, I was hoping I could simply alter this function to do as i wish above.
See: http://unity3d.com/support/documentation/ScriptReference/Application-runInBackground.html
Yes, I know about that function, but you can't access how it deter$$anonymous$$es if the game is in the background or not, nor can you just... change what it does (APIs don't work like that). Like I said, you need to write a C++ plugin if you want to deter$$anonymous$$e when your game has lost focus or not.
$$anonymous$$aybe there are differences what functions (Events, Updates, ...) are called in the last frame the application has focus? $$anonymous$$aybe coroutines aren't paused the same way as the normal execution loop? Here is the calling order: http://forum.unity3d.com/viewtopic.php?t=2719 ... Just some thoughts, I haven't tried it out.
I'm wondering if I can manipulate the auto-mated pause to try and get the game to detect when it's been paused, and have it un-pause and open the desired menu ins$$anonymous$$d. I'll fiddle with this myself and if either solution is plausible, I'll post my findings.
Answer by lathomas64 · Jul 07, 2010 at 06:42 PM
what if you create a screen-wide transparent gui element and use OnMouseExit to pull up your escape menu.
http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.OnMouseExit.html
Answer by googler · Jul 23, 2013 at 01:39 PM
The same problem. OnApplicationFocus detects minimizing only on Windows, but I need on Mac too.
Answer by BobbyDoogle · Jun 14, 2015 at 08:42 PM
Has anything been updated in 5.0+ to support this, I'm looking at the same problem now.
Your answer
![](https://koobas.hobune.stream/wayback/20220613061956im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
I am creating a pause button and when I click it the score keeps rising. How can I stop it? 1 Answer
A Proper Way To Pause A Game 9 Answers
show pause menu issues 1 Answer
OnMouseDown not firing 2 Answers
Pause not working correctly 1 Answer