What is the fastest (and best) way to show Frames Per Seconds in a Unity game?
There’s an FPS script in the Script Tutorial example project (installed in Shared). But this one is nicer imho:
/// This behavior script changest the GUI text on the object
/// it is attached to to display a frames per second counter.
var updateFrequency = 1.0;
private var oldCount = 0;
private var oldTime = 0.0;
while (true) {
guiText.text = ((Time.frameCount - oldCount) / (Time.time - oldTime)).ToString ("#,##0.0");
oldCount = Time.frameCount;
oldTime = Time.time;
yield new WaitForSeconds (updateFrequency);
}
… create a GUI Text object, then attach this script to it (by dragging it)
Doh, that was a bit silly… I had forgotten about private variables in JavaScript. I’ve edited the script above to simplify it.
d.
Thanks a lot David!
Good stuff to know, thanx. Jeff