Skip to content

Instantly share code, notes, and snippets.

@ZeredaGames
Created December 27, 2015 06:29
Show Gist options
  • Save ZeredaGames/ea250447d085e5da68f6 to your computer and use it in GitHub Desktop.
Save ZeredaGames/ea250447d085e5da68f6 to your computer and use it in GitHub Desktop.
private var gui : GUIText;
private var updateInterval = 1.0;
private var lastInterval : double; // Last interval end time
private var frames = 0; // Frames over current interval
function Start()
{
lastInterval = Time.realtimeSinceStartup;
frames = 0;
}
function OnDisable ()
{
if (gui)
DestroyImmediate (gui.gameObject);
}
function Update()
{
#if !UNITY_FLASH
++frames;
var timeNow = Time.realtimeSinceStartup;
if (timeNow > lastInterval + updateInterval)
{
if (!gui)
{
var go : GameObject = new GameObject("FPS Display", GUIText);
go.hideFlags = HideFlags.HideAndDontSave;
go.transform.position = Vector3(0,0,0);
gui = go.guiText;
gui.pixelOffset = Vector2(5,55);
}
var fps : float = frames / (timeNow - lastInterval);
var ms : float = 1000.0f / Mathf.Max (fps, 0.00001);
gui.text = ms.ToString("f1") + "ms " + fps.ToString("f2") + "FPS";
frames = 0;
lastInterval = timeNow;
}
#endif
}
@ZeredaGames
Copy link
Author

Old and doesn't work in Unity any longer.

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