【Unity】NGUI实现技能冷却脚本

来源:互联网 发布:vb源码下载 编辑:程序博客网 时间:2024/04/30 11:48
using UnityEngine;
using System.Collections;


public class Skill_cold : MonoBehaviour {


    public UISprite cold_icon;
    public float coldTime = 3f;
    private bool startCold = false;




//Use this for initialization
void Start() 
{
        
        
}

//Update is called one per frame
void Update() 
{
        if (Input.GetKeyDown(KeyCode.A) && startCold==false  )
        {
            cold_icon.fillAmount = 1;
            startCold = true;
        }

Colding();
        
}


    void Colding() //正在冷却方法
    {
        if (startCold)
        {
            //速度乘以时间间隔
            cold_icon.fillAmount -= (1f / coldTime) * Time.deltaTime;
            if (cold_icon.fillAmount <= 0.05f) //当小于一定值时,判定已经冷却完毕
            {
                cold_icon.fillAmount = 0;
                startCold = false;
            }


        }
    }


    

}



技能遮罩的图片类型如上图所示Type设为Filled

0 0
原创粉丝点击