コガネブログ

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

【Unity】using を使用して Application.targetFrameRate を設定するクラス

ソースコード

使用例

using Kogane;
using System.Collections;
using UnityEngine;

public class Example : MonoBehaviour
{
    private void Update()
    {
        if ( Input.GetKeyDown( KeyCode.Space ) )
        {
            StartCoroutine( Hoge() );
        }
    }

    private IEnumerator Hoge()
    {
        using ( new TargetFrameRateScope( 30 ) )
        {
            yield return new WaitForSeconds( 3 );
        }
    }

    private void OnGUI()
    {
        GUILayout.Label( Application.targetFrameRate.ToString() );
    }
}