Tracking the numbers
When the mouse cursor is near the left edge of the screen, you get negative numbers. When it's closer to the right edge, you get positive numbers. And, if you try to position your cursor at exactly the halfway point, you get zero. This makes sense. We know that when the mouse is at the left edge, Input.mousePosition.x
is zero. If we subtract half of the screen width from zero (on my monitor, that's 640 pixels), we get -640 at the left edge instead.
My screen is 1280 pixels wide, so I'm using 640 to represent half of its width. Your mileage may vary! Common screen widths are 800, 1024, 1152, 1280, 1600, or 1920.
When the mouse is in the middle of the screen, Input.mousePosition.x
is 640
. It's at the halfway point. If we subtract half the screen width (640 in my case), we get zero.
When the mouse position is at the right edge of the screen, Input.mousePosition.x
is almost at 1280 on my 1280-pixel-wide display (again, your mileage may vary). Subtract half the Screen.width
...