- Home /
Getting position of Game Window
Hi there, is there a way to get the location of the game window and probably the monitor resolution in game? I'm basically making a game where I want the player to sometimes drag the window around the screen or partly off screen sometimes. Also as a bonus if there's a way to tell when the players are dragging it that'd be great too. I realize this may be beyond unity's access to the system but it would be great.
Thanks for any help!
I'll try to post again as an answer depending on my results, but at least for the window position, I'll be using the mouse as a reference between the standalone and the monitor screen values.
For that, you need Input.mousePosition and System.Windows.Forms.Cursor.Position. Doing some simple math can give you the window coordinates through the properties above, since the standalone gives you the correct values. Input.mousePosition will be negative if needed for example. I'm trying this method to reduce the dll requirements.
For the drag the window part, if you stabilish the difference between those coordinates above, this difference will change if the standalone window moves, so in a way you can tell if the window is moving around.
Answer by LK84 · Jan 05, 2017 at 06:09 PM
It's possible for Windows applications with DLL import from user32.dll. A Similiar question has been asked here before: http://answers.unity3d.com/questions/13523/is-there-a-way-to-set-the-position-of-a-standalone.html
There is a GetWindow method too which you can use https://msdn.microsoft.com/de-de/library/windows/desktop/ms633515(v=vs.85).aspx
For detecting dragging: https://msdn.microsoft.com/en-us/library/windows/desktop/ms646256(v=vs.85).aspx
@L$$anonymous$$84 Is it possible to set the window position in Linux?
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Get notification from command line or other application when a printer finish printng? 1 Answer
Why Doesn't Unity App Fit Microsoft Surface Screen? 0 Answers
FunkyGlowingThingsEffect fix for inverted y on Windows 1 Answer
Windows Standalone Crashes in -batchmode , how do I read the strack from the log? 1 Answer