Unity--计算FPS
原创
©著作权归作者所有:来自51CTO博客作者4562xse3460的原创作品,请联系作者获取转载授权,否则将追究法律责任
FPS:每秒运行的帧数。
using UnityEngine;
public class Fps : MonoBehaviour
{
private float m_LastTime;
private float m_UpdateInterval = 0.5f;
private float m_Frames;
void Start()
{
m_Frames = 0;
m_LastTime = Time.realtimeSinceStartup;
}
void Update()
{
m_Frames++;
float curTime = Time.realtimeSinceStartup;
// 每0.5s更新一次
if(curTime > m_LastTime + m_UpdateInterval)
{
float fps = m_Frames / (curTime - m_LastTime);
Debug.Log("The Fps: " + fps);
}
}
}