Skip to content

Instantly share code, notes, and snippets.

@loyio
Created January 14, 2024 02:35
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 loyio/6cd02b699abe3d5489ad972518176be4 to your computer and use it in GitHub Desktop.
Save loyio/6cd02b699abe3d5489ad972518176be4 to your computer and use it in GitHub Desktop.
Unity Fps Display Script
using UnityEngine;
public class FpsDisplay : MonoBehaviour
{
float _deltaTime = 0.0f;
void Update()
{
_deltaTime += (Time.unscaledDeltaTime - _deltaTime) * 0.1f;
}
void OnGUI()
{
int w = Screen.width, h = Screen.height;
GUIStyle style = new GUIStyle();
Rect rect = new Rect(200, 200, w, h * 2 / 100);
style.alignment = TextAnchor.UpperLeft;
style.fontSize = h * 5 / 100;
style.normal.textColor = new Color (0.0f, 1.0f, 0.0f, 1.0f);
float msec = _deltaTime * 1000.0f;
float fps = 1.0f / _deltaTime;
string text = $"{msec:0.0} ms ({fps:0.} fps)";
GUI.Label(rect, text, style);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment