So I have this code that calculates the frame rate, and displays it on the screen. In the Unity editor is seems to work fine, but when I upload it to the computer and test it, my frame rates doesn’t exceed 60. Is there something wrong with my code, because I’m sure I should have a frame rate higher than 60.
using UnityEngine;
using System.Collections;
public class HUDFPS : MonoBehaviour
{
float deltaTime = 0.0f;
float fps;
float msec;
private float timeleft = 0.0f;
private float updateInterval = 1.0f;
void Start()
{
// timeleft = updateInterval;
}
void Update()
{
deltaTime += (Time.deltaTime - deltaTime) * 0.1f;
timeleft -= Time.deltaTime;
}
void OnGUI()
{
if (timeleft <= 0.0f)
{
fps = 1.0f / deltaTime;
msec = deltaTime * 1000.0f;
timeleft = updateInterval;
}
GUIStyle style = new GUIStyle ();
Rect rect = new Rect (10, 5, 1000, 30);
//float msec = deltaTime * 1000.0f;
style.normal.textColor = (fps >= 30) ? Color.green : ((fps > 10) ? Color.yellow : Color.red);
string text = string.Format ("{0:0.0} ms ({1:0.} fps)", msec, fps);
GUI.Label (rect, text, style);
}
}