diff --git a/Role/Role.cs b/Role/Role.cs index e5373ee..f9ce56d 100644 --- a/Role/Role.cs +++ b/Role/Role.cs @@ -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().direction = HurtDirectin; go.GetComponent().CreateText(); diff --git a/Role/move/2D/SimplePathfindingDoTween.cs b/Role/move/2D/SimplePathfindingDoTween.cs index cfa27c5..0fbd8fd 100644 --- a/Role/move/2D/SimplePathfindingDoTween.cs +++ b/Role/move/2D/SimplePathfindingDoTween.cs @@ -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;