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); }