赞
踩
目录
- private Image progressBar;
- private float currentProgress = 0;
- /// <summary>
- /// 进度条需要持续的时长
- /// </summary>
- private float duration = 5f;//这个时间可以任意定义
-
- private void ProgressBar()
- {
- currentProgress += Time.deltaTime;
- progressBar.fillAmount = currentProgress / duration;
- if (currentProgress >= duration)
- {
- progressBar.fillAmount = 1;
- }
- }
- private Text showText;//展示的Text
- private float time = 5f;//指定的时间
- private float currentVaule = 0f;//起始值
- private float targetVaule = 115f;//目标值
- /// <summary>
- /// 数据递增
- /// </summary>
- public void DataIncrement()
- {
- currentVaule += Time.deltaTime * (targetVaule / time);
-
- if (currentVaule >= targetVaule)
- {
- currentVaule = targetVaule;
- }
- showText.text = currentVaule.ToString("0000.00");
- }
- /**
- * start要与max的值保持一致
- * **/
- private float start = 10;//此值为开始递减的默认值
- private float max = 10;//修改此值设置递减比例
- public float duration = 3f;//持续时间
- private float timer;
- /// <summary>
- /// 在规定时间内从一个值递减到0
- /// </summary>
- private void DataDecrement()
- {
- if (start > 0)
- {
- start -= max * Time.deltaTime / duration;
- timer += Time.deltaTime;
- if (timer >= 1)
- {
- Debug.LogError(timer);
- timer = 0;
- }
- }
- else
- start = 0;
- }
注:以上方法需放在Update中调用执行
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。