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 ...

Get Unity 4.x Game Development by Example Beginner's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.