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 ...

Get Unity 3D Game Development by Example 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.