using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FPS : MonoBehaviour {
float lastFPSTime;
int curFrameCount;
string curFPS = "";
void Start () {
}
void OnGUI()
{
OnShowFPS();
}
void OnShowFPS()
{
if (lastFPSTime == 0)
{
lastFPSTime = Time.time;
curFrameCount = Time.frameCount;
curFPS = "";
}
else
{
float curTime = Time.time;
if (curTime >= lastFPSTime + 1.0f)
{
int n = Time.frameCount - curFrameCount;
float dt = curTime - lastFPSTime;
curFPS = string.Format("FPS:{0:.00}", n / dt);
lastFPSTime = curTime;
curFrameCount = Time.frameCount;
}
GUI.skin.label.fontSize = 28;
GUI.contentColor = Color.white;
GUI.Label(new Rect(480, 10, 200, 100), curFPS);
}
}
}
Unity 显示FPS
最新推荐文章于 2024-10-11 11:50:35 发布