sourcePosition | The origin of the ray. |
targetPosition | The end of the ray. |
hit | Holds the properties of the ray cast resulting location. |
passableMask | A mask specifying which NavMesh layers can be passed when tracing the ray. |
Trace a line between two points on the NavMesh.
hit
parameter. This can be used to check if there is a clear
shot or line of sight between a character and a target object.
This function is preferable to the similar Physics.Raycast
because the line tracing is performed in a simpler way using the navmesh
and has a lower processing overhead.var target: Transform; function Update () { var hit: NavMeshHit; // Note the negative test condition! Using -1 for the mask // indicates all layers are to be used. if (!NavMesh.Raycast(transform.position, target.position, hit, -1)) { // Target is "visible" from our position. } }
using UnityEngine; using System.Collections; public class Example : MonoBehaviour { public Transform target; void Update() { NavMeshHit hit; if (!NavMesh.Raycast(transform.position, target.position, out hit, -1)) { } } }
import UnityEngine import System.Collections public class Example(MonoBehaviour): public target as Transform def Update() as void: hit as NavMeshHit if not NavMesh.Raycast(transform.position, target.position, , -1): pass