描述
Singleton class 用于访问被烘培好的 NavMesh.
使用NavMesh类可以执行空间查询(spatial queries),例如路径查找和可步行性测试。此类还允许您设置特定区域类型的寻路成本,并调整寻路和避免的全局行为。
静态属性(Static Properties)
AllAreas
区域遮罩常数,包括所有NavMesh区域。
NavMesh.AllAreas
public static int AllAreas;
遮罩(mask)可用于查询函数,如(NavMesh.Raycast)光线投射,用来指定所有被接受的导航网格区域类型(NavMesh area types )。
// TargetReachable
using UnityEngine;
using UnityEngine.AI;
public class TargetReachable : MonoBehaviour
{
public Transform target;
private NavMeshHit hit;
private bool blocked = false;
void Update()
{
// Allow pass through all area types when testing if the target position
// is reachable from the transform location.
blocked = NavMesh.Raycast(transform.position, target.position, out hit, NavMesh.AllAreas);
Debug.DrawLine(transform.position, target.position, blocked ? Color.red : Color.green);
if (blocked)
Debug.DrawRay(hit.position, Vector3.up, Color.red);
}
}
面板配置
绘制导航网格
可寻路效果展示
不可寻路效果展示