From 8fec6273a4346583fb36152f04a9a9ac7c7f00dc Mon Sep 17 00:00:00 2001 From: GL <2365963573@qq.com> Date: Fri, 20 Dec 2024 21:41:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=86=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Role/Bullet.cs | 13 +++++++++++- Role/Role.cs | 12 ++++++++++++ Role/move/2D/SimplePathfindingDoTween.cs | 25 +++++++++++++++++++++++- 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/Role/Bullet.cs b/Role/Bullet.cs index 442fa9a..d5cf18a 100644 --- a/Role/Bullet.cs +++ b/Role/Bullet.cs @@ -164,9 +164,20 @@ public class Bullet : MonoBehaviour Debug.Log("创建火焰"); } } + if (bulletAttributes == BulletAttributes.Water) + { + if (effectPre != null) + { + GameObject go = Instantiate(effectPre, collision.transform); + go.transform.position = new Vector2(collision.transform.position.x, collision.transform.position.y-0.2f); + collision.transform.GetComponent().SlowDown(0.2f, 3f); + - + } + } + + } } } private float lastDamageTime = 0f; diff --git a/Role/Role.cs b/Role/Role.cs index 1263401..1cad827 100644 --- a/Role/Role.cs +++ b/Role/Role.cs @@ -47,6 +47,7 @@ public class Role : Fun [Header("自己的画布")]public Canvas _Canvas; [Header("自己的图片")] public SpriteRenderer spriteRenderers; // 存储所有的SpriteRenderer组件 [Header("被打的方向")] public int HurtDirectin; + public float Hp { @@ -254,6 +255,17 @@ public class Role : Fun } + /// + /// 角色减速 + /// + public void SlowDown(float num) + { + Navigation.speedFactor *= num; + } + + + + /// /// 单位更新buff /// diff --git a/Role/move/2D/SimplePathfindingDoTween.cs b/Role/move/2D/SimplePathfindingDoTween.cs index b46ad73..cfa27c5 100644 --- a/Role/move/2D/SimplePathfindingDoTween.cs +++ b/Role/move/2D/SimplePathfindingDoTween.cs @@ -20,6 +20,7 @@ public class SimplePathfindingDoTween : Fun Vector3 Vector3 = new Vector3(); public Tween pathTween; + public float speedFactor=1;//速度因子 [Header("旋转的动画")]public GameObject obj; public void MoveToNextWaypoint(GameObject gameObject, float moveSpeed) @@ -51,7 +52,16 @@ public class SimplePathfindingDoTween : Fun // 使用DoTween的DOPath来平滑地移动 pathTween=gameObject.transform.DOPath(path, timeToReach, PathType.Linear) .SetEase(Ease.Linear) - .OnUpdate(() => RotateTowardsTarget()); // 每次更新时调整旋转 + .OnUpdate(() => { + + + pathTween.timeScale = speedFactor; + + RotateTowardsTarget(); } + + + + ); // 每次更新时调整旋转 } else @@ -65,7 +75,20 @@ public class SimplePathfindingDoTween : Fun transform.DOPause(); } + // 控制DoTween的速度,接受一个新的速度因子和一个恢复时间 + public void ChangeSpeed(float newSpeedFactor, float restoreTime) + { + // 改变路径动画的速度因子 + pathTween.timeScale = newSpeedFactor; + // 设置一个延迟恢复原始速度的功能 + DOTween.To(() => 0f, x => { }, 0f, restoreTime).OnKill(() => + { + Debug.Log("设置减速+++++++++++++++++"); + // 在延迟结束后恢复原来的速度 + pathTween.timeScale = 1f; // 恢复原速度 + }); + } public void StopPathDoTween(float stopTime)//暂停移动 { // 暂停当前的动画