diff --git a/xiaofang/Assets/Script/npc/RecuseNpc.cs b/xiaofang/Assets/Script/npc/RecuseNpc.cs index 2e45ab89..55edc855 100644 --- a/xiaofang/Assets/Script/npc/RecuseNpc.cs +++ b/xiaofang/Assets/Script/npc/RecuseNpc.cs @@ -37,6 +37,9 @@ public class RecuseNpc : MonoBehaviour // 存目的地的list public List targetPoints = new List(); + + + private void Awake() { instance = this; @@ -84,7 +87,17 @@ public class RecuseNpc : MonoBehaviour public void SetNpcDes(Vector3 tar) { //target.position = tar; + NavMeshHit hit; + if (!NavMesh.SamplePosition(tar, out hit, 1.0f, NavMesh.AllAreas)) + { + Debug.LogError($"目标点 {target} 不在导航网格上"); + } + else + { + tar = hit.position; // 将目标点调整到最近的导航网格位置 + } targetPoints.Add(tar); + } private void Update()