How to detect in which half of the screen the cursor is, no matter the resolution?

I know how to get how far from the lower left corner the cursor is, in X and Y. And I know how to detected how fast the cursor is moving, in X and Y. But I have no idea on how to detect the cursor based on the center of the screen.

Is this possible? To know if it is in the lower or upper half, and in the left or right half, no matter the resolution of the game window?

I appreciate any help.

You know how reality always comes back to inform us that nothing is all that simple?


Basically you must inquire from Unity what the size of the window is. The app can run in a Windowed mode or full screen mode, so you have to ask yourself if you’re more interested in the center of the Window on display (when it isn’t full screen), or the screen hardware no matter where the window is.


You’re probably most interested in the Window. You begin your research with this documentation on Screen, a class that tells all about that current display resolution and the size of the window the application is showing (which are the same in full screen mode).


Once you know that (say, Screen.width), you know that the center in X is width / 2, center in Y is height / 2, and the rest becomes obvious.