Information about a position that is the result of a query ran on the NavMesh.
The object represents a valid result if the distance and position properties have finite values. Otherwise, the object represents a result that could not be calculated from the input data provided to the query. Refer to the documentation of each query method for details about the situations that produce invalid results.
Note: You can use float.isFinite() to determine whether a value is finite.
using UnityEngine; using UnityEngine.AI; public class ShowLineOfSightToTarget : MonoBehaviour { public Transform target; NavMeshHit m_RayEnd; void Update() { // Detect whether a NavMesh edge blocks a straight path to the target. NavMesh.Raycast(transform.position, target.position, out m_RayEnd, NavMesh.AllAreas); var isRaySegmentOnNavMesh = float.IsFinite(m_RayEnd.distance); if (isRaySegmentOnNavMesh) { Debug.DrawLine(transform.position, m_RayEnd.position, m_RayEnd.hit ? Color.red : Color.green); Debug.DrawLine(m_RayEnd.position, target.position, Color.gray); if (m_RayEnd.hit) { Debug.DrawLine(m_RayEnd.position, m_RayEnd.position + Vector3.up, Color.red); Debug.DrawLine(m_RayEnd.position, m_RayEnd.position + m_RayEnd.normal, Color.yellow); } } else { Debug.DrawLine(transform.position, target.position, Color.magenta); } } }