Files
FutureMen2/Assets/_FutureMen2/Scripts/UI/BloodSlider.cs
2026-01-05 11:00:50 +08:00

65 lines
1.5 KiB
C#
Raw Blame History

using TMPro;
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;
public class BloodSlider : MonoBehaviour
{
public Image blood1;
public Image blood2;
public TextMeshProUGUI enemyName;
public GameObject damageUIPre;
public Transform damageUIPos;
private void Start()
{
if(blood1 == null)
return;
blood1.fillAmount = 1;
blood2.fillAmount = 1;
}
public void CreateDamagePre(float damage, bool criticalHit)
{
GameObject damageUI = Instantiate(damageUIPre, transform);
float offsetX = Random.Range(-100f, 100f);
float offsetY = Random.Range(-40f, 25f);
damageUI.transform.localPosition = damageUIPos.localPosition+new Vector3(offsetX,offsetY,0);
damageUI.GetComponent<DamageUI>().ShowDamage(damage, criticalHit);
}
public void SetName(string name)
{
enemyName.text = name;
}
public void SetValue(float value)
{
if (value <= 0)
gameObject.SetActive(false);
else
gameObject.SetActive(true);
blood1.fillAmount = value;
}
public void SetValue2(float currentBlood, float totalBlood)
{
float value = currentBlood / totalBlood;
DOTween.To(() => blood2.fillAmount, x => blood2.fillAmount = x, value, 0.5f);//Ѫ<><D1AA><EFBFBD>
blood1.fillAmount = value;
}
private void Update()
{
transform.parent.GetComponent<Transform>().LookAt(GameInit.Ins.playerCam.transform);
}
}