UI技能CD倒计时

来源:互联网 发布:淘宝贷款最多贷多少钱 编辑:程序博客网 时间:2024/05/16 11:18
    using UnityEngine;    using System.Collections;    using UnityEngine.UI;    public class SkillCoolingManager : MonoBehaviour    {     public KeyCode key;     public Text text;
     //冷却时间,可外界设置     public float coldTime = 2;     private Image masks;     private float timer = 0;     private bool isStart = false;     private void Start()     {        masks = transform.Find("Mask").GetComponent<Image>();
        //一开始将技能CD的时间制空        text.text = null;     }     private void Update()     {        1.这个是从外界定义按键        if (Input.GetKeyDown(key))        {            isStart = true;        }        if (isStart)        {            timer += Time.deltaTime;            masks.fillAmount = (coldTime - timer) / coldTime;            //让float 变成 int             text.text = ((int)(coldTime-timer)).ToString();            if (timer >= coldTime)            {                masks.fillAmount = 0;                timer = 0;                isStart = false;
                //CD完成也制空                text.text = null;            }        }     }     2.外界去添加点击事件     public void OnClick()     {        isStart = true;     }    }

原创粉丝点击