Time for action – making the hands and tray follow the mouse

Any script that we create in Unity is reusable, and we can attach scripts to multiple GameObjects. Let's attach our MouseFollow script to the HandsAndTray GameObject.

  1. Find the MouseFollow script in the Project panel (I put mine inside a "Scripts" folder), and drag it onto the HandsAndTray GameObject in the Hierarchy panel. (Make sure to drop it on the parent HandsAndTray GameObject, not the child handsAndTray model.)
  2. Test your game by pressing the Play button.

The hands and tray should follow your mouse the very same way the paddle does. Because we generated a collider on the tray in the FBXImporter settings, the Ball should bounce on the tray just as it does with the Paddle.

The only trouble ...

Get Unity 4.x Game Development by Example Beginner's Guide 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.