Skip to content

Instantly share code, notes, and snippets.

@mstevenson
Last active Jul 25, 2022
Embed
What would you like to do?
An accurate FPS counter for Unity. Works in builds.
using UnityEngine;
using System.Collections;
public class Fps : MonoBehaviour
{
private float count;
private IEnumerator Start()
{
GUI.depth = 2;
while (true)
{
count = 1f / Time.unscaledDeltaTime;
yield return new WaitForSeconds(0.1f);
}
}
private void OnGUI()
{
GUI.Label(new Rect(5, 40, 100, 25), "FPS: " + Mathf.Round(count));
}
}
@TAKiKAXD
Copy link

TAKiKAXD commented Sep 23, 2021

good

@leonlol-dev
Copy link

leonlol-dev commented May 11, 2022

good

@moffatjason
Copy link

moffatjason commented Jun 27, 2022

good

@Erfan-Sheikh
Copy link

Erfan-Sheikh commented Jul 11, 2022

good

@morwoen
Copy link

morwoen commented Jul 24, 2022

Use Time.unscaledDeltaTime instead, so that you can continue to calculate an accurate FPS while the Time.timeScale is not 1.

@mstevenson
Copy link
Author

mstevenson commented Jul 25, 2022

Replaced with Time.unscaledDeltaTime, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment