From ddc46a22efdad2c66aed3f2f56a383c39ba831eb Mon Sep 17 00:00:00 2001 From: huyulong <1838407198@qq.com> Date: Fri, 13 Dec 2024 19:33:27 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E5=8A=A8=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- xiaofang/Assets/Script/npc/RecuseNpc.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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()