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 - animate the Paddle

  1. Add this line of code beneath the existing line of code:
    Debug.Log(Input.mousePosition.x);
    
  2. Your entire Script should look like this:
    function Update () {
    transform.position.x = Input.mousePosition.x;
    Debug.Log(Input.mousePosition.x);
    }
    
  3. Save and test your game.

Look at the very bottom of the screen for the results of your Debug.Log() statement. As you move the mouse cursor left and right, you'll see this number changing. It goes from 0 when your mouse is at the left edge, and rapidly increases. The upper limit depends on your monitor resolution; on my screen, Input.mousePosition.x maxes out at 1279! Earlier, a value of 2 put the paddle nearly all the way off the screen. With Debug.Log() reporting these numbers, ...

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