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
本文介绍如何使用NGUI插件实现技能冷却效果。通过创建精灵并使用脚本控制其填充量来模拟冷却过程。提供了具体的Unity脚本实例。

511

被折叠的 条评论
为什么被折叠?



