201808032029->unity中关于update_fixedupdate_invokerepeting

在项目中遇到了一个需求

一个方块集需要在非常小的时间内环形轮询并操作

一开始我直接用的dotween

发觉dotween只适合做1秒以上的缓动动画

如果播放动画的时间少于特定的时间

dotween则会跳过某些集

可能这是dotween的机制问题吧

于是在大神的指导下

介绍了一下invokerepeting

//------------------------------------------------------------------------

public class qq2222 : MonoBehaviour
{
    public GameObject Invoke2;
    private float invokeTime = 0;

    public GameObject Update2;
    private float updateTime = 0;

    public GameObject FixedUpdate2;
    private float fixedTime = 0;

    // Use this for initialization
    private void Start()
    {
        invokeTime = 0;
        InvokeRepeating("InvokeMoveCube", 0, 0.001f);
    }

    private void InvokeMoveCube()
    {
        ++invokeTime;
        Invoke2.transform.PositionX(invokeTime);
    }

    // Update is called once per frame
    private void Update()
    {
        ++updateTime;
        Update2.transform.PositionX(updateTime);
    }

    private void FixedUpdate()
    {
        ++fixedTime;
        FixedUpdate2.transform.PositionX(fixedTime);
    }
}

//------------------------------------------------------------------------

代码里边写的是3个物体在invokerepeting和update和fixedupdate里变化的值给指定物体

其实就是用于比较3个物体哪个跑得快

哪个跑得快就知道哪个方案适合做快速环形轮询动画了

结果是

0.5秒后

invoke物体的x坐标 : 86f

update物体的x坐标:25f

fixedupdate物体的x坐标:38f

2秒后

invoke物体的x坐标 : 339f

update物体的x坐标:112f

fixedupdate物体的x坐标:117f

5秒后

invoke物体的x坐标 : 883f

update物体的x坐标:301f

fixedupdate物体的x坐标:283f

10秒后

invoke物体的x坐标 : 1877f

update物体的x坐标:647f

fixedupdate物体的x坐标:585f

猜你喜欢

转载自blog.csdn.net/qq_28902031/article/details/81394043