add
This commit is contained in:
parent
c16e71b11b
commit
bd7bc9cfad
@ -161,10 +161,10 @@ public class Role : Fun
|
||||
// 如果启用 MonoBehaviour,则每个固定帧速率的帧都将调用此函数
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (!isAnimationPlay)
|
||||
{
|
||||
updateAnimation();
|
||||
}
|
||||
//if (!isAnimationPlay)
|
||||
//{
|
||||
// updateAnimation();
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,20 +1,13 @@
|
||||
|
||||
using UnityEngine;
|
||||
using DG.Tweening; // 引入DoTween命名空间
|
||||
|
||||
public class SimplePathfindingDoTween : Fun
|
||||
{
|
||||
public Transform[] waypoints; // 预设的路径点
|
||||
public float moveDuration = 1f; // 每个点之间的移动时长
|
||||
public float moveSpeed = 1f; // 控制移动速度的参数(更高值表示更快的速度)
|
||||
|
||||
private int currentWaypointIndex = 0; // 当前路径点的索引
|
||||
|
||||
//void Start()
|
||||
//{
|
||||
// // 让角色开始移动到第一个路径点
|
||||
// MoveToNextWaypoint();
|
||||
//}
|
||||
|
||||
public void MoveToNextWaypoint(GameObject gameObject)
|
||||
{
|
||||
if (currentWaypointIndex < waypoints.Length)
|
||||
@ -22,11 +15,23 @@
|
||||
// 获取下一个路径点
|
||||
Transform targetWaypoint = waypoints[currentWaypointIndex];
|
||||
|
||||
// 使用DoTween实现平滑移动到目标位置
|
||||
gameObject.transform.DOMove(targetWaypoint.position, moveDuration)
|
||||
.OnComplete(() => MoveToNextWaypoint(gameObject)); // 移动完成后继续到下一个路径点
|
||||
// 计算路径点之间的距离
|
||||
float distance = Vector3.Distance(gameObject.transform.position, targetWaypoint.position);
|
||||
|
||||
// 根据设置的速度计算时间
|
||||
float timeToReach = distance / moveSpeed; // 根据速度控制匀速移动的时间
|
||||
|
||||
// 使用DoTween的DOPath来平滑地移动到目标位置
|
||||
Vector3[] path = new Vector3[waypoints.Length - currentWaypointIndex];
|
||||
for (int i = 0; i < path.Length; i++)
|
||||
{
|
||||
path[i] = waypoints[currentWaypointIndex + i].position;
|
||||
}
|
||||
|
||||
// 执行路径动画,保证匀速前进
|
||||
gameObject.transform.DOPath(path, timeToReach, PathType.Linear)
|
||||
.SetEase(Ease.Linear); // 设置匀速
|
||||
|
||||
currentWaypointIndex++; // 更新路径点索引
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user