Time for action – create a new MouseFollow Script
In the Project panel, right-click/alternate-click on an empty chunk of space and navigate to Create | JavaScript. Alternatively, you can navigate to Assets | Create | JavaScript in the menu at the top of the screen, or use the Create button at the top of the Project panel.
A new Script is added to the Project panel. Name it
MouseFollow
.Drag-and-drop your new
MouseFollow
Script onto your Paddle GameObject.Double-click to open the Script in MonoDevelop. 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; }
Add a Rigidbody component to Paddle by navigating to Component | Physics | Rigidbody.
In the Inspector panel, find the Rigidbody component and check box next to Is Kinematic. The Unity manual warns against moving colliders around through code without adding a Rigidbody component because it could...