using UnityEngine; using DG.Tweening; // 引入DoTween命名空间 public class SimplePathfindingDoTween : Fun { public Transform[] waypoints; // 预设的路径点 public float moveDuration = 1f; // 每个点之间的移动时长 private int currentWaypointIndex = 0; // 当前路径点的索引 //void Start() //{ // // 让角色开始移动到第一个路径点 // MoveToNextWaypoint(); //} void MoveToNextWaypoint(GameObject gameObject) { if (currentWaypointIndex < waypoints.Length) { // 获取下一个路径点 Transform targetWaypoint = waypoints[currentWaypointIndex]; // 使用DoTween实现平滑移动到目标位置 gameObject.transform.DOMove(targetWaypoint.position, moveDuration) .OnComplete(() => MoveToNextWaypoint(gameObject)); // 移动完成后继续到下一个路径点 currentWaypointIndex++; // 更新路径点索引 } else { Debug.Log("到达终点!"); } } }