hit | Holds the properties of the resulting location. |
Locate the closest NavMesh edge.
private var agent: NavMeshAgent; function Start () { agent = GetComponent.<NavMeshAgent>(); } function Update() { // Move to the nearest wall when the mouse is clicked. if (Input.GetMouseButtonDown(0)) { TakeCover(); } } function TakeCover() { var hit: NavMeshHit; if (agent.FindClosestEdge(hit)) { agent.SetDestination(hit.position); } }
using UnityEngine; using System.Collections; public class Example : 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); } }
import UnityEngine import System.Collections public class Example(MonoBehaviour): private agent as NavMeshAgent def Start() as void: agent = GetComponent[of NavMeshAgent]() def Update() as void: if Input.GetMouseButtonDown(0): TakeCover() def TakeCover() as void: hit as NavMeshHit if agent.FindClosestEdge(): agent.SetDestination(hit.position)