Skip to content

Instantly share code, notes, and snippets.

@RoyLab
Created June 3, 2017 09:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RoyLab/0eeba6d96d8b741a1e44bef2ddd04450 to your computer and use it in GitHub Desktop.
Save RoyLab/0eeba6d96d8b741a1e44bef2ddd04450 to your computer and use it in GitHub Desktop.
FPSDisplay
using UnityEngine;
using System.Collections;
public class FPSDisplay : MonoBehaviour
{
float deltaTime = 0.0f;
void Update()
{
deltaTime += (Time.deltaTime - deltaTime) * 0.1f;
}
void OnGUI()
{
int w = Screen.width, h = Screen.height;
GUIStyle style = new GUIStyle();
Rect rect = new Rect(0, 0, w, h * 2 / 100);
style.alignment = TextAnchor.UpperLeft;
style.fontSize = h * 2 / 100;
style.normal.textColor = new Color (0.0f, 0.0f, 0.5f, 1.0f);
float msec = deltaTime * 1000.0f;
float fps = 1.0f / deltaTime;
string text = string.Format("{0:0.0} ms ({1:0.} fps)", msec, fps);
GUI.Label(rect, text, style);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment