欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Unity 技能冷却条

程序员文章站 2022-04-03 08:38:30
...
using UnityEngine;
using UnityEngine.UI;
///<summary>
///技能冷却条
///</summary>
public class SkillItem : MonoBehaviour
{

    public float coldTime = 2f;
    private float timer = 0f;   //
    private Image filledImage;
    private bool isStartTimer; 
    // Start is called before the first frame update
    void Start()
    {
        filledImage = transform.Find("FilledSkill").GetComponent<Image>();
    }

    // Update is called once per frame
    void Update()
    {
        if(isStartTimer){
            timer += Time.deltaTime;
            filledImage.fillAmount = (coldTime-timer)/coldTime;
        }
        if(timer >= coldTime){
            filledImage.fillAmount = 0;
            timer = 0;
            isStartTimer = false;
        }
    }
    public void OoClick(){
        isStartTimer = true;
    }
}

 

相关标签: Unity 笔记