暂停修改

This commit is contained in:
GL 2024-12-24 10:58:35 +08:00
parent 4b6941d72b
commit 4e4e313bb2
2 changed files with 25 additions and 2 deletions

View File

@ -84,7 +84,7 @@ public class Role : Fun
{
hit();
Debug.LogError("僵直效果,被注释了");
//Navigation.StopPathDoTween(0.2f); // 停止任何进行中的 DoTween 动画0.2s为示例值
Navigation.StopPathDoTween(0.2f); // 停止任何进行中的 DoTween 动画0.2s为示例值
GameObject go = GameObject.Instantiate(HpTextPrefab, _Canvas.transform);
go.GetComponent<SnowHpControl>().direction = HurtDirectin;
go.GetComponent<SnowHpControl>().CreateText();

View File

@ -89,18 +89,41 @@ public class SimplePathfindingDoTween : Fun
pathTween.timeScale = 1f; // 恢复原速度
});
}
public void StopPathDoTween(float stopTime)//暂停移动
private bool isTweenPaused = false; // 标志,检查是否已经暂停
private float accumulatedStopTime = 0f; // 累计的暂停时间
public void StopPathDoTween(float stopTime) // 暂停移动
{
if (isTweenPaused)
{
// 如果已经暂停,累加新的暂停时间
accumulatedStopTime += stopTime;
return;
}
// 暂停当前的动画
pathTween.Pause();
isTweenPaused = true;
// 插入一个自定义的延迟(僵直时间)
DOTween.To(() => 0f, x => { }, 0f, stopTime).OnKill(() =>
{
// 在延迟结束后恢复动画
pathTween.Play();
isTweenPaused = false;
// 如果有累积的暂停时间,继续暂停
if (accumulatedStopTime > 0f)
{
// 使用累计的暂停时间来暂停
StopPathDoTween(accumulatedStopTime);
accumulatedStopTime = 0f; // 重置累积时间
}
});
}
void RotateTowardsTarget()
{
Vector3 _vector3 = Vector3 - gameObject.transform.position;