Framerate counter

I have made/found a simple framerate counter, but the weird thing is the result, it is not the same as the stats give in the fps section.

var updateInterval : float = 0.5;

private var frames : int; // Frames drawn over the interval
private var timeleft : float; // Left time for current interval
private var accum : float;
var highestFPS : float;
var fps : float;
 
function Update() {
    timeleft -= Time.deltaTime;
    frames++;
    accum += Time.timeScale/Time.deltaTime;
    
    if(timeleft <= 0.0) {
    	fps = accum/frames;
	    if (fps > highestFPS) {
	    	highestFPS = fps;
	    }
	    accum = 0.0f;
        timeleft = updateInterval;
        frames = 0;
    }
}

Try doing it in FixedUpdate().

If the differences in results are minor (like 29.9 instead of 29.8), it’s probably just rounding somewhere in the chain and nothing to worry about.

If it’s a major difference (like 60.0 vs. 30.0) then you probably screwed up your code =]