用NGUI做一个计时条!

时间:2023-03-09 20:36:51
用NGUI做一个计时条!

1、建立两个UISprite。

2、建立脚本CountingTime

3、编写脚本

public class CountTime : MonoBehaviour
{
//时间计时器
public float countTime;
//倒计时显示
public UILabel timeCount; //计时条在准备后隐藏
public float prograssPercent = 1f; public UISprite jinDuTiao;
// Update is called once per frame
void Update()
{
if (countTime <= 60 )
{
countTime += Time.deltaTime;
timeCount.text = (60f - countTime).ToString("F0");
prograssPercent -= (1f / 60f) * Time.deltaTime;
jinDuTiao.fillAmount = prograssPercent;
}
}
}

用NGUI做一个计时条!

用NGUI做一个计时条!

用NGUI做一个计时条!

主要是UIsprite.fillAmount的应用,注意Fill Dir要改成Horizontal,水平。

写的一般,不知道大家能不能理解,慢研究吧,哈哈!