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 - create a new MouseFollow Script

  1. In the Project panel, right-click on an empty chunk of space and choose Create | JavaScript. Alternatively, you can click on Assets | Create | JavaScript in the menu at the top of the screen, or use the Create button at the top of the Project panel.
  2. A new Script is added to the Project panel, with the default name NewBehaviourScript.
  3. Rename the Script MouseFollow.
  4. Drag-and-drop your new MouseFollow Script onto your Paddle Game Object.

    Just as before, we're going to add a single, simple line of code inside the curly braces (sandwich buns) of the Update function (sandwich):

    function Update () {
    transform.position.x = 2;
    }
    
  5. Save the Script and press Play to test your game. Like pulling the chair out ...

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