您的位置:首页 > 移动开发 > Unity3D

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

2013-07-25 15:04 691 查看
NGUI非常强大我们今天来学习一下,如何利用NGUI做技能冷却的CD效果。先导入NGUI的插件。没有的话这里有啊NGUI2.6.3下载地址: http://vdisk.weibo.com/s/KLqn5

创建一个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;
			}
			
		}
		
		
	}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: