A tiny bit o' math

This code's not going to work. Our paddle moves only to the right, along the positive X-axis, because we're working only with positive numbers. We need some negative numbers in there so that the paddle will move to the left at some point. But, at what point?

Hmm… what if we take half of the screen's width and subtract it from Input.mousePosition.x? What does that do for us?

A quick trip to Unity Script Reference tells us how to find the width of the screen in pixels. Let's divide that number by 2 and subtract it from the mouse position.

Change the Debug.Log() function call to look like this:

Debug.Log(Input.mousePosition.x - Screen.width/2);

Save and test. Watch the bottom of the screen for the result.

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.