unity WaitForFixedUpdate在物理帧的最后执行
作者:互联网
WaitForFixedUpdate在物理帧的最后执行:
https://docs.unity3d.com/Manual/ExecutionOrder.html
Time.frameCount是逻辑帧自增,和物理帧无关
https://answers.unity.com/questions/933751/timeframecount-vs-timerenderedframecount.html
IEnumerator CountDown_WaitForFixedUpdate() { Debug.Log("1yield WaitForFixedUpdate - step " + Time.frameCount + " fixedCount:" + fixedCount); yield return new WaitForFixedUpdate(); Debug.Log("2yield WaitForFixedUpdate - step " + Time.frameCount + " fixedCount:" + fixedCount); //yield return new WaitForFixedUpdate(); // Debug.Log("3yield WaitForFixedUpdate - step " + Time.frameCount); } public new Coroutine StartCoroutine(IEnumerator enumerator) { return base.StartCoroutine(ToFixedUpdate(enumerator)); } IEnumerator ToFixedUpdate(IEnumerator a) { while (a.MoveNext()) { var cur = a.Current; if (cur == null) cur = new WaitForFixedUpdate(); yield return cur; } } // Update is called once per frame void Update() { Debug.LogError("Update " + Time.frameCount); } private static int fixedCount = 0; private void FixedUpdate() { fixedCount = fixedCount + 1; Debug.LogError("0 FixedUpdate " + Time.frameCount + " fixedCount:" + fixedCount); Debug.LogError("1 FixedUpdate " + Time.frameCount + " fixedCount:" + fixedCount); this.StartCoroutine(CountDown_WaitForFixedUpdate()); Debug.LogError("2 FixedUpdate " + Time.frameCount + " fixedCount:" + fixedCount); }
标签:cur,fixedCount,unity,Time,Debug,WaitForFixedUpdate,frameCount,物理 来源: https://www.cnblogs.com/sun-shadow/p/15788141.html