数值变化跳动效果

csharp 复制代码
 public Text txt;

    private int num;

    private float _timers=10;
    private int _target;

    public void Set(float index)
    {
        txt.text = index.ToString();
    }

    public void Go(int target)
    {
        _target = target;
        num = int.Parse(txt.text);
        StopCoroutine("IReduce");
        StartCoroutine("IReduce");
    }

    IEnumerator IReduce()
    {
        float offset = (num - _target) / _timers;
        if (Mathf.Abs(offset) < 1)
        {
            txt.text = _target.ToString();
            yield break;
        }

        for (int i = 0; i < _timers; i++)
        {
            num =(int)(num-offset);
            txt.text = num.ToString();
            if (i == _timers-1)
            {
                txt.text = _target.ToString();
            }
            yield return new WaitForSeconds(0.1f);
        }
    }
相关推荐
二哈喇子!4 小时前
BOM模型
开发语言·前端·javascript·bom
二哈喇子!4 小时前
Vue2 监听器 watcher
前端·javascript·vue.js
yanyu-yaya4 小时前
前端面试题
前端·面试·前端框架
二哈喇子!5 小时前
使用NVM下载Node.js管理多版本
前端·npm·node.js
GGGG寄了5 小时前
HTML——文本标签
开发语言·前端·html
2501_944521596 小时前
Flutter for OpenHarmony 微动漫App实战:推荐动漫实现
android·开发语言·前端·javascript·flutter·ecmascript
Amumu121387 小时前
Vue核心(三)
前端·javascript·vue.js
CoCo的编程之路7 小时前
2026 前端效能革命:如何利用智能助手实现“光速”页面构建?深度横评
前端·人工智能·ai编程·comate·智能编程助手·文心快码baiducomate
RFCEO7 小时前
HTML编程 课程五、:HTML5 新增语义化标签
前端·html·html5·跨平台·语义化标签·可生成安卓/ios·html最新版本
2501_944521597 小时前
Flutter for OpenHarmony 微动漫App实战:图片加载实现
android·开发语言·前端·javascript·flutter·php