描述
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);}
}
面板配置
繪制導航網格
可尋路效果展示
不可尋路效果展示