码迷,mamicode.com
首页 > 其他好文 > 详细

CD冷却效果实现

时间:2014-08-31 17:11:51      阅读:255      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   for   2014   div   cti   

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

bubuko.com,布布扣

在上图中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;
            }
        }
    }
}

 

CD冷却效果实现

标签:style   blog   http   color   io   for   2014   div   cti   

原文地址:http://www.cnblogs.com/hometown/p/3947851.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!