怪物扣血变红和僵直
This commit is contained in:
parent
d266869186
commit
5dbbd278a6
33
Role/Role.cs
33
Role/Role.cs
@ -12,7 +12,7 @@ using UnityEngine.UI;
|
|||||||
using UnityEngine.UIElements;
|
using UnityEngine.UIElements;
|
||||||
using Debug = UnityEngine.Debug;
|
using Debug = UnityEngine.Debug;
|
||||||
using Image = UnityEngine.UI.Image;
|
using Image = UnityEngine.UI.Image;
|
||||||
|
using DG.Tweening;
|
||||||
public enum Camp
|
public enum Camp
|
||||||
{/// <summary>
|
{/// <summary>
|
||||||
/// 玩家
|
/// 玩家
|
||||||
@ -43,6 +43,7 @@ public class Role : Fun
|
|||||||
[Header("hp填充")] public Image Hpfiil;
|
[Header("hp填充")] public Image Hpfiil;
|
||||||
[Header("扣血填充")] public GameObject HpTextPrefab;
|
[Header("扣血填充")] public GameObject HpTextPrefab;
|
||||||
[Header("自己的画布")]public Canvas _Canvas;
|
[Header("自己的画布")]public Canvas _Canvas;
|
||||||
|
[Header("自己的图片")] public SpriteRenderer spriteRenderers; // 存储所有的SpriteRenderer组件
|
||||||
|
|
||||||
public float Hp
|
public float Hp
|
||||||
{
|
{
|
||||||
@ -63,6 +64,8 @@ public class Role : Fun
|
|||||||
GameObject go = GameObject.Instantiate(HpTextPrefab, _Canvas.transform);
|
GameObject go = GameObject.Instantiate(HpTextPrefab, _Canvas.transform);
|
||||||
|
|
||||||
go.GetComponent<Text>().text= (temp - hp).ToString();
|
go.GetComponent<Text>().text= (temp - hp).ToString();
|
||||||
|
FlashRedEffect();
|
||||||
|
StopDoTween(0.2f);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -292,4 +295,32 @@ 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