Created
January 14, 2024 02:35
-
-
Save loyio/6cd02b699abe3d5489ad972518176be4 to your computer and use it in GitHub Desktop.
Unity Fps Display Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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