Instantly share code, notes, and snippets.

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 {
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