프로그래밍/유니티

[유니티] FPS 표기

갓똥 2022. 10. 5. 15:36
728x90
반응형
[Header("[Fps Option]")]
public int textSize = 48;
private float _fpsTime;

private void OnGUI()
{
    int w = Screen.width;
    int h = Screen.height;

    GUIStyle style = new GUIStyle();

    Rect rect = new Rect(20.0f, 0, w, h * 0.02f);
    style.alignment = TextAnchor.UpperLeft;
    style.fontSize = textSize;
    style.normal.textColor = Color.white;

    float msec = _fpsTime * 1000.0f;
    float fps = 1.0f / _fpsTime;
    string text = $"{msec:0.0} ms ({fps:0.} fps)";

    GUI.Label(rect, text, style);
}

private void Update()
{
    _fpsTime += (Time.unscaledDeltaTime - _fpsTime) * 0.1f;
}

// Application.targetFrameRate = 480; 최대 프레임 제한
728x90
반응형