From 0a6cdaed3f15c98ddc4b75ffa6d4593bfaeeff41 Mon Sep 17 00:00:00 2001 From: GL <2365963573@qq.com> Date: Tue, 24 Dec 2024 14:56:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=8C=E4=BA=BA=E5=86=B0=E5=86=BB=E5=8F=97?= =?UTF-8?q?=E5=87=BB=E5=8F=98=E8=93=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Role/Bullet.cs | 20 ++++++++++++++------ Role/Role.cs | 39 +++++++++++++++++++++++++++------------ 2 files changed, 41 insertions(+), 18 deletions(-) diff --git a/Role/Bullet.cs b/Role/Bullet.cs index 825e64e..3dc0e3e 100644 --- a/Role/Bullet.cs +++ b/Role/Bullet.cs @@ -153,11 +153,17 @@ public class Bullet : MonoBehaviour Collider2D.enabled = false;//关闭碰撞体 transform.position = collision.transform.position; animator.SetTrigger("Boom"); - Debug.Log("爆炸动画+++++++++++++++++++++++++++++++++"); + } } - if (bulletAttributes==BulletAttributes.Fire) + if (bulletAttributes == BulletAttributes.Not)//无属性 + { + Crole.FlashRedEffect(); + + } + + if (bulletAttributes==BulletAttributes.Fire)//火 { if (effectPres.Count==1) @@ -165,22 +171,23 @@ public class Bullet : MonoBehaviour GameObject go = Instantiate(effectPres[0], collision.transform); go.transform.position = new Vector2(collision.transform.position.x, collision.transform.position.y + 0.2f); go.GetComponent().bullet = this; - + Crole.FlashRedEffect(); Debug.Log("创建火焰"); } } } - if (bulletAttributes == BulletAttributes.Water) + + if (bulletAttributes == BulletAttributes.Water)//水 { if (effectPres.Count > 1) { GameObject go = Instantiate(effectPres[Random.Range(0,effectPres.Count-1)], collision.transform); go.transform.position = new Vector2(collision.transform.position.x, collision.transform.position.y-0.2f); collision.transform.GetComponent().SlowDown(0.2f, 3f); - + Crole.FlashRedEffect(1,3f); - } + } } @@ -210,6 +217,7 @@ public class Bullet : MonoBehaviour { Crole.bloodLoss(new object[] { Crole, role.DamageCreate(), attackObj.damageTyp, role }); + Crole.FlashRedEffect(); lastDamageTime = Time.time; } diff --git a/Role/Role.cs b/Role/Role.cs index d13628b..94d4d36 100644 --- a/Role/Role.cs +++ b/Role/Role.cs @@ -91,7 +91,7 @@ public class Role : Fun go.GetComponent().direction = HurtDirectin; go.GetComponent().CreateText(); go.GetComponent().text = (temp - hp).ToString("F0"); // 显示伤害值 - FlashRedEffect(); // 血量减少时的红色闪烁效果 + //FlashRedEffect(); // 血量减少时的红色闪烁效果 } @@ -401,22 +401,37 @@ public class Role : Fun // 如果有其他需要重置的状态,可以在这里添加 } - private void FlashRedEffect() + public void FlashRedEffect(int color = 0, float time = 0.2f)//0、1 红、蓝 { - // 遍历所有的SpriteRenderer组件,让它们变红 - - if (spriteRenderer != null) + // 如果spriteRenderer存在 + if (spriteRenderer != null) + { + // 创建一个Sequence来确保动画按顺序执行 + Sequence sequence = DOTween.Sequence(); + + // 颜色变化 + if (color == 0) { - spriteRenderer.DOColor(UnityEngine.Color.red, 0.2f) - .OnComplete(() => - { - // 恢复原始颜色 - spriteRenderer.DOColor(UnityEngine.Color.white, 0.2f); - }); + // 变为红色并恢复白色 + sequence.Append(spriteRenderer.DOColor(UnityEngine.Color.red, 0.2f)) + .Append(spriteRenderer.DOColor(UnityEngine.Color.white, time)); } - + else if (color == 1) + { + // 更冷的深蓝色 + UnityEngine.Color frostBlueWithAlpha = new UnityEngine.Color(0.2f, 0.5f, 1f); ; // 冰冻蓝色 + + // 变为蓝色并恢复白色 + sequence.Append(spriteRenderer.DOColor(frostBlueWithAlpha, 0.2f)) + .Append(spriteRenderer.DOColor(UnityEngine.Color.white, time)); + } + + // 开始执行Sequence + sequence.Play(); + } } + public void StopDoTween(float stopTime) { // 暂停当前的动画