Unity 利用NGUI2.6.3做技能冷却的CD效果

NGUI非常强大我们今天来学习一下,如何利用NGUI做技能冷却的CD效果。先导入NGUI的插件。没有的话这里有啊创建一个plane,

然后,再创建一个sprite。

 

 

 

脚本代码与sprite相关联就OK了!

using UnityEngine;
using System.Collections;

public class Main : MonoBehaviour {

        UISprite sprite;
        void Awake()
        {
                sprite = GetComponent<UISprite>();

        }

        void Update()
        {
                sprite.fillAmount -= 0.01f;

        }

}

补充如何获取UIButton中的UISprite

using UnityEngine;
using System.Collections;

public class Attack_DBTX : MonoBehaviour {

        UISprite sprite;
        private bool cd_bool = false;

        // Use this for initialization
        void Start () {
        sprite = gameObject.GetComponentInChildren<UISprite>();

                Debug.Log(sprite.name);
        }

        void OnClick()
        {
                cd_bool = true;

        }
        // Update is called once per frame
        void Update () {

                if(cd_bool)
                {
                        sprite.fillAmount -= 0.01f;
                        if(sprite.fillAmount == 0)
                        {
                                sprite.fillAmount = 1;
                                cd_bool = false;
                        }

                }

        }
}

NGUI2.6.3下载地址: http://vdisk.weibo.com/s/KLqn5

http://unity3d.9ria.com/?p=4804

原文链接:http://www.unitymanual.com/thread-5195-1-1.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值