We can show a debug ray from a moving object to its destination tile by creating the MouseOverHighlighter C# script class with the following contents. We then add an instance object as a component to the NavMeshAgent component's controlled Sphere-arrow GameObject:
using UnityEngine;
using UnityEngine.AI;
public class DebugRaySourceDestination : MonoBehaviour {
void Update() {
Vector3 origin = transform.position;
Vector3 destination = GetComponent<NavMeshAgent>().destination;
Vector3 direction = destination - origin;
Debug.DrawRay(origin, direction, Color.yellow);
}
}
The preceding code uses the current position of the character (transform.position – our moment origin) and the destination point (GetComponent<NavMeshAgent>().destination) as the two endpoints to display a yellow debug ray.