数值变化跳动效果

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);
        }
    }
相关推荐
恋恋风尘hhh7 分钟前
滑动验证码前端安全研究:以顶象(dingxiang-inc)为例
前端·安全
懂懂tty7 小时前
React状态更新流程
前端·react.js
小码哥_常7 小时前
告别繁琐!手把手教你封装超实用Android原生Adapter基类
前端
skywalk81638 小时前
pytest测试的时候这是什么意思?Migrating <class ‘kotti.resources.File‘>
前端·python
一只蝉nahc8 小时前
vue使用iframe内嵌unity模型,并且向模型传递信息,接受信息
前端·vue.js·unity
子兮曰9 小时前
Bun v1.3.12 深度解析:新特性、性能优化与实战指南
前端·typescript·bun
2401_885885049 小时前
易语言彩信接口怎么调用?E语言Post实现多媒体数据批量下发
前端
a1117769 小时前
Three.js 的前端 WebGL 页面合集(日本 开源项目)
前端·javascript·webgl
Kk.080210 小时前
项目《基于Linux下的mybash命令解释器》(一)
前端·javascript·算法
小李子呢021110 小时前
前端八股---闭包和作用域链
前端