Time for action – Log the New Number

  1. Change your Debug.Log() call so that it looks like this:
        Debug.Log( (Input.mousePosition.x -Screen.width/2) /  (Screen.width/2) );

Ack! So many brackets! We use those brackets because we want the division and subtraction stuff to happen in the right sequence. You may remember order of operations rules from algebra class. BEDMAS: evaluate the Brackets first, then the Exponents, then Division, Multiplication, Addition, and finally Subtraction.

To wrap your brain around it, here's what we're doing, in pseudocode:

(first thing)/(second thing)

We're dividing something by something else. The first thing is the -640 to 640 number range that we cooked up. The second thing is Screen.width/2 (the screen's midpoint). We ...

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.