数值变化跳动效果

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);
        }
    }
相关推荐
默_笙41 分钟前
🛴 从散件到整机:DeepAgents 与 Agent 身上预留的那些"插槽"(前置介绍)
前端·javascript
zhangzeyuaaa1 小时前
深入理解 Ruby 运算符:本质、分类、坑点与重载实战
开发语言·前端·ruby
一木 之林1 小时前
DeepSeek Agent 开发(一)
开发语言·前端·javascript
树下水月2 小时前
Typora破解
linux·服务器·前端
用户5508492902562 小时前
CSS布局实战:从Flex到Grid的完整避坑指南
前端
用户5508492902563 小时前
前端接口请求层怎么封装?一个可落地的请求方案
前端
MetWeave3 小时前
跟着一条 SPECI 走流水线:从电报到界面
前端
Helix2503 小时前
Chrome 开发者工具进阶:长截图、网络调试与性能分析
前端·chrome·chrome devtools·使用技巧·性能分析·开发者工具·长截图
liangshanbo12153 小时前
面试题:Webpack 的 publicPath 有什么作用?
前端·webpack·node.js
mjhcsp4 小时前
DeepSeek V4.1 Flash 批量处理效能实测
java·前端·数据库