CD冷却效果实现

在NGUI中实现CD转圈的特效,可以用图片控件中UISprite组件的Fill Amount属性去控制。

在上图中skill表示需要冷却技能的图片;其子控件Label表示右下角的快捷键“Y”;子控件Sprite表示覆盖在其上的一张图片(本例是一张空的半透明的图片);

using UnityEngine;
using System.Collections;

public class CDCold : MonoBehaviour {

    private float coldTime=2;
    private bool isColding=false;
    private UISprite sprite;

    // Use this for initialization
    void Awake () {
        sprite = transform.Find ("Sprite").GetComponent<UISprite> ();
    }
    
    // Update is called once per frame
    void Update () {
    if (Input.GetKey (KeyCode.Y) && isColding == false) 
        {
            isColding=true;
            sprite.fillAmount=1;
        }
        if (isColding) 
        {
            sprite.fillAmount-=(1.0f/coldTime)*Time.deltaTime;
            if(sprite.fillAmount<=0.0f)
            {
                sprite.fillAmount=0;
                isColding=false;
            }
        }
    }
}
原文地址:https://www.cnblogs.com/hometown/p/3947851.html