怪物扣血变红和僵直
This commit is contained in:
parent
d266869186
commit
5dbbd278a6
39
Role/Role.cs
39
Role/Role.cs
@ -12,7 +12,7 @@ using UnityEngine.UI;
|
||||
using UnityEngine.UIElements;
|
||||
using Debug = UnityEngine.Debug;
|
||||
using Image = UnityEngine.UI.Image;
|
||||
|
||||
using DG.Tweening;
|
||||
public enum Camp
|
||||
{/// <summary>
|
||||
/// 玩家
|
||||
@ -43,7 +43,8 @@ public class Role : Fun
|
||||
[Header("hp填充")] public Image Hpfiil;
|
||||
[Header("扣血填充")] public GameObject HpTextPrefab;
|
||||
[Header("自己的画布")]public Canvas _Canvas;
|
||||
|
||||
[Header("自己的图片")] public SpriteRenderer spriteRenderers; // 存储所有的SpriteRenderer组件
|
||||
|
||||
public float Hp
|
||||
{
|
||||
get => hp;
|
||||
@ -63,7 +64,9 @@ public class Role : Fun
|
||||
GameObject go = GameObject.Instantiate(HpTextPrefab, _Canvas.transform);
|
||||
|
||||
go.GetComponent<Text>().text= (temp - hp).ToString();
|
||||
|
||||
FlashRedEffect();
|
||||
StopDoTween(0.2f);
|
||||
|
||||
}
|
||||
|
||||
if (hp <= 0)
|
||||
@ -291,5 +294,33 @@ public class Role : Fun
|
||||
|
||||
// 如果有其他需要重置的状态,可以在这里添加
|
||||
}
|
||||
|
||||
|
||||
private void FlashRedEffect()
|
||||
{
|
||||
// 遍历所有的SpriteRenderer组件,让它们变红
|
||||
|
||||
if (spriteRenderer != null)
|
||||
{
|
||||
spriteRenderer.DOColor(UnityEngine.Color.red, 0.2f)
|
||||
.OnComplete(() =>
|
||||
{
|
||||
// 恢复原始颜色
|
||||
spriteRenderer.DOColor(UnityEngine.Color.white, 0.2f);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void StopDoTween(float stopTime)
|
||||
{
|
||||
// 暂停当前的动画
|
||||
transform.DOPause();
|
||||
|
||||
// 插入一个自定义的延迟(僵直时间)
|
||||
DOTween.To(() => 0f, x => { }, 0f, stopTime).OnKill(() =>
|
||||
{
|
||||
// 在延迟结束后恢复动画
|
||||
transform.DOPlay();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user