O'Reilly logo

Unity 3D Game Development by Example by Ryan Henson Creighton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 and Multiplication, and finally, Addition and 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). ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required