Untitled
unknown
swift
2 years ago
857 B
6
Indexable
//File Name: FPS.cs
//Description: This code is scraped from the Unity documentation and is
//just used to print the current frame rate to the screen.
using UnityEngine;
public class FPS : 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(0, 0, w, h * 2 / 100);
style.alignment = TextAnchor.UpperLeft;
style.fontSize = h * 6 / 100;
style.normal.textColor = new Color(1.0f, 1.0f, 1.0f, 1.0f);
float msec = deltaTime * 1000.0f;
float fps = 1.0f / deltaTime;
string text = string.Format("{36.576} ms ({120.0} fps)", msec, fps);
GUI.Label(rect, text, style);
}
}Editor is loading...