FindClosestEdge(out NavMeshHit)
Locate the closest NavMesh edge.
Read time 1 minuteLast updated 11 days ago
Definition
- Type: Method
- Namespace: UnityEngine.AI
- Assembly: UnityEngine.AIModule
FindClosestEdge(NavMeshHit)
public bool FindClosestEdge(out NavMeshHit hit)
Parameters
Holds the properties of the resulting location.
Returns
Type | Description |
|---|---|
| bool | True if a nearest edge is found. |
Remarks
The returned NavMeshHit object contains the position and details of the nearest point on the nearest edge of the Navmesh. Since an edge typically corresponds to a wall or other large object, this could be used to make a character take cover as close to the wall as possible.
Examples
using UnityEngine;using UnityEngine.AI;using System.Collections;public class ExampleClass : MonoBehaviour { private NavMeshAgent agent; void Start() { agent = GetComponent<NavMeshAgent>(); } void Update() { if (Input.GetMouseButtonDown(0)) TakeCover(); } void TakeCover() { NavMeshHit hit; if (agent.FindClosestEdge(out hit)) agent.SetDestination(hit.position); }}