using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class Skill : MonoBehaviour { public Text text; public Image image; public float coolDown = 0f; public float coolDonwTime = 10f; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { if (coolDown > 0) { // deltaTime 是当前Update执行和上一次Update执行的时间差 // 用来拟合计算现实时间,不受帧率的影响。 coolDown -= Time.deltaTime; text.text = coolDown.ToString("f1"); image.fillAmount = coolDown / coolDonwTime; } else { coolDown = 0f; text.text = ""; } } public void UseSkill() { if(coolDown > 0) { } else { // 释放技能,并进入冷却 /* 释放技能的代码 */ coolDown = coolDonwTime; } } }