using System.Collections; using System.Collections.Generic; using TMPro; using UnityEngine; using UnityEngine.UI; using UnityEngine.UIElements; public class CoolDown : MonoBehaviour { public float MaxTime = 10; // 当前技能最大冷却时间 private float CoolTime = 0; // 当前冷却的时间 public UnityEngine.UI.Image mask; // 当前遮罩的image组件 // Start is called before the first frame update void Update() { if(CoolTime>0) { CoolTime -= Time.deltaTime; CoolShow(); } else { CoolTime = 0; GetComponentInChildren().SetText(""); } } public void InUse() { if (CoolTime == 0) { CoolTime = MaxTime; Camera.main.GetComponent().Hp += 10; Camera.main.GetComponent().SetHp(); } } void CoolShow() { GetComponentInChildren().SetText(CoolTime.ToString("F2")); mask.fillAmount = CoolTime/MaxTime; } }