Last active
May 2, 2020 08:55
-
-
Save cnra/06f2c8b1c0545673c4e705bfd65a94da to your computer and use it in GitHub Desktop.
unity display fps #unity
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
/*Original Code: http://wiki.unity3d.com/index.php?title=FramesPerSecond */ | |
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class DisplayFPS : 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