- Home /
can you focus and unfocus your unity program
I am making a program with unity where I was going to make the program come to the front of the the screen. I was going to make it do this like every 15 min. and when I say front of the screen I mean over other windows like a internet browser. Is there a way to do this.
Answer by jonas-echterhoff · Mar 29, 2011 at 12:52 PM
Only by writing a plugin.
I think this would be the easiest way to go about with the current feature set of Unity3D.
Answer by Statement · Mar 29, 2011 at 01:37 PM
The best way I could get about is to set screen resolution. This pops up the window on my machine but only if the the player first was fullscreen and then is windowed, and that it isn't minimized but just behind any other window. So it's probably not really ideal for your needs. For some reason I don't seem to get OnApplicationFocus event when I tab out of a fullscreen game...
Anyhow if you're interested anyway, here's my code for this test:
var popupTimer : float = 5; Application.runInBackground = true;
function OnApplicationFocus (focus : boolean) { if (focus) CancelInvoke("Restore"); else InvokeRepeating("Restore", popupTimer, popupTimer); }
function Restore() { Screen.SetResolution(Screen.currentResolution.width, Screen.currentResolution.height, Screen.fullScreen, Screen.currentResolution.refreshRate); }
Yeah, I said it ain't ideal since you have to first go fullscreen, then windowed, and then not $$anonymous$$imize it. $$anonymous$$ake sure you read my whole answer.
This is more of a hack than a solution. I wouldn't count on it working predictably.
Thanks for the workaround. Got useful 7 years later with little modifications. I need to focus my game window when a match is found, in case user $$anonymous$$imized or alt+tabed it.
So I just use SetResolution to set game fullscreen and then use a 0.01f Invoke to return it to original windowed size. Game window focused. Works like a charm with no DLL needed.
Your answer
Follow this Question
Related Questions
C# Tooltips through multiple windows 1 Answer
Game with 2 separate windows 2 Answers
Easy way to make buttons in-accessible when under a pop-up window? 1 Answer
Editor window full screen 2 Answers