using System.Collections; using System.Collections.Generic; using UnityEngine; using DG.Tweening; public class npcMove : MonoBehaviour { public List path=new List(); public float moveNeedTimer; public void Init(List path,float moveNeedTimer) { this.path = path; this.moveNeedTimer = moveNeedTimer; // 将路径点转换为 Vector3 数组 Vector3[] pathPoints = new Vector3[this.path.Count]; for (int i = 0; i < path.Count; i++) { pathPoints[i] = path[i].position; } // 使用 DOPath 沿着路径移动到目标点,并禁用旋转变化 this.transform.DOPath(pathPoints, moveNeedTimer, PathType.Linear) .SetOptions(false) // 禁用旋转 .SetEase(Ease.InOutSine) .WaitForCompletion(); } }