Go where I'm looking

In this next script, instead of being random, we'll send Ethan to wherever we look. In Unity, this is accomplished by using ray casting—like shooting a ray from the camera and seeing what it hits (for more information, visit http://docs.unity3d.com/Manual/CameraRays.html).

We're going to create a new script, which will be attached to WalkTarget like before, as follows:

  1. Select the WalkTarget object in the Hierarchy panel or the Scene view.
  2. In its Inspector panel, click on the Add Component button.
  3. Select New Script.
  4. Name it LookMoveTo.
  5. Ensure that the C Sharp language is selected.
  6. Click on Create and Add.

This should create a script component on the WalkTarget object. Double-click on it to open it in the MonoDevelop code editor.

The ...

Get Unity Virtual Reality Projects 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.