コガネブログ

平日更新を目標に Unity や C#、Visual Studio、ReSharper などのゲーム開発アレコレを書いていきます

【Unity】LateFixedUpdate の実装例

ソースコード

using System.Collections;
using UnityEngine;

[DisallowMultipleComponent]
public sealed class Example : MonoBehaviour
{
    private void OnEnable()
    {
        StartCoroutine( nameof( UpdateLateFixedUpdate ) );
    }

    private void OnDisable()
    {
        StopCoroutine( nameof( UpdateLateFixedUpdate ) );
    }

    private IEnumerator UpdateLateFixedUpdate()
    {
        var waitForFixedUpdate = new WaitForFixedUpdate();

        while ( true )
        {
            yield return waitForFixedUpdate;
            LateFixedUpdate();
        }
    }

    private void FixedUpdate()
    {
        Debug.Log( nameof( FixedUpdate ) );
    }

    private void LateFixedUpdate()
    {
        Debug.Log( nameof( LateFixedUpdate ) );
    }
}

使用例

FixedUpdate の後に LateFixedUpdate が呼び出される