Skip to content

Instantly share code, notes, and snippets.

@hoverbird
Forked from mstevenson/Fps.cs
Created July 25, 2019 05:00
Show Gist options
  • Save hoverbird/babeb35b06bbf00aa6c8584691e58df7 to your computer and use it in GitHub Desktop.
Save hoverbird/babeb35b06bbf00aa6c8584691e58df7 to your computer and use it in GitHub Desktop.
An accurate FPS counter for Unity. Works in builds.
using UnityEngine;
using System.Collections;
public class Fps : MonoBehaviour {
string label = "";
float count;
IEnumerator Start ()
{
GUI.depth = 2;
while (true) {
if (Time.timeScale == 1) {
yield return new WaitForSeconds (0.1f);
count = (1 / Time.deltaTime);
label = "FPS :" + (Mathf.Round (count));
} else {
label = "Pause";
}
yield return new WaitForSeconds (0.5f);
}
}
void OnGUI ()
{
GUI.Label (new Rect (5, 40, 100, 25), label);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment