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