May 2018
Beginner
492 pages
11h 53m
English
In our script, each time Update() is called, we'll read where the camera is pointing (by using its transform position and rotation), cast a ray in that direction, and ask Unity to tell us where it hits the ground plane. Then, we'll use this location to set the WalkTarget object's position.
Here's the full LookMoveTo.cs script:
using UnityEngine; using System.Collections; public class LookMoveTo : MonoBehaviour { public GameObject ground; void Update () { Transform camera = Camera.main.transform; Ray ray; RaycastHit hit; GameObject hitObject; Debug.DrawRay (camera.position, camera.rotation * Vector3.forward * 100.0f); ray = new Ray (camera.position, camera.rotation * Vector3.forward); if (Physics.Raycast (ray, out hit)) ...Read now
Unlock full access