x


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,

more ▼

asked Jun 12 '10 at 08:20 PM

Ezzerland gravatar image

Ezzerland
66 1 1 8

There is no function to determine this, since that's strictly a Windows problem (Something similar exists on Mac, but it's a little different, and you can never "minimize" 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).

Jun 12 '10 at 08:52 PM qJake

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

Jun 12 '10 at 10:03 PM Ezzerland

Yes, I know about that function, but you can't access how it determines 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 determine when your game has lost focus or not.

Jun 13 '10 at 02:30 AM qJake

Maybe there are differences what functions (Events, Updates, ...) are called in the last frame the application has focus? Maybe 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.

Jun 13 '10 at 10:45 AM felix.

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 instead. I'll fiddle with this myself and if either solution is plausible, I'll post my findings.

Jun 15 '10 at 08:46 PM Ezzerland
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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

more ▼

answered Jul 07 '10 at 06:42 PM

lathomas64 gravatar image

lathomas64
178 6 7 19

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3457
x261
x11

asked: Jun 12 '10 at 08:20 PM

Seen: 3037 times

Last Updated: Jun 12 '10 at 08:32 PM