Version: 2017.3

NavMeshAgent.FindClosestEdge

切换到手册
public bool FindClosestEdge (out AI.NavMeshHit hit);

参数

hit 保留所生成位置的属性。

返回

bool 如果找到最近边缘,则为 true。

描述

找到最近的导航网格边缘。

返回的 NavMeshHit 对象包含 导航网格最近边缘上的 最近点的位置和详细信息。由于边缘通常对应于墙或者其他大型对象, 因此这可用于使一个角色尽可能靠近墙隐蔽。

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { private AI.NavMeshAgent agent; void Start() { agent = GetComponent<AI.NavMeshAgent>(); } void Update() { if (Input.GetMouseButtonDown(0)) TakeCover(); } void TakeCover() { AI.NavMeshHit hit; if (agent.FindClosestEdge(out hit)) agent.SetDestination(hit.position); } }