Created
December 27, 2015 06:29
-
-
Save ZeredaGames/ea250447d085e5da68f6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Old and doesn't work in Unity any longer.