diff --git a/xiaofang/Assets/Script/npc/RecuseNpc.cs b/xiaofang/Assets/Script/npc/RecuseNpc.cs index 3c895936..03220152 100644 --- a/xiaofang/Assets/Script/npc/RecuseNpc.cs +++ b/xiaofang/Assets/Script/npc/RecuseNpc.cs @@ -88,20 +88,21 @@ public class RecuseNpc : MonoBehaviour { Debug.Log(tar+"目标路径点"); - //target.position = tar; - //Debug.Log(target); - //NavMeshHit hit; - //if (!NavMesh.SamplePosition(tar, out hit, 1.0f, NavMesh.AllAreas)) - //{ - // Debug.LogError($"目标点 {target} 不在导航网格上"); - //} - //else - //{ - // tar = hit.position; // 将目标点调整到最近的导航网格位置 - //} - //Debug.Log("进入奔跑++++++="); - //targetPoints.Add(tar); - navMeshAgent.SetDestination(tar); + target.position = tar; + Debug.Log(target); + NavMeshHit hit; + if (!NavMesh.SamplePosition(tar, out hit, 1.0f, NavMesh.AllAreas)) + { + Debug.LogError($"目标点 {target} 不在导航网格上"); + } + else + { + tar = hit.position; // 将目标点调整到最近的导航网格位置 + } + Debug.Log("进入奔跑++++++="); + targetPoints.Clear(); + targetPoints.Add(tar); + }