An FPS counter.

本文由博主(YinaPan)原创,转载请注明出处:http://www.cnblogs.com/YinaPan/p/Unity_FPFCounter.html 
using UnityEngine;
using System.Collections; // An FPS counter.
// It calculates frames/second over each updateInterval,
// so the display does not keep changing wildly.
public class Test : MonoBehaviour {
public float updateInterval = 0.5F;
private double lastInterval;
private int frames = ;
private float fps;
void Start() {
lastInterval = Time.realtimeSinceStartup;
frames = ;
}
void OnGUI() {
GUILayout.Label("fps:" + fps.ToString("f2"));
}
void Update() {
++frames;
float timeNow = Time.realtimeSinceStartup;
if (timeNow > lastInterval + updateInterval) {
fps = (float)(frames / (timeNow - lastInterval));
frames = ;
lastInterval = timeNow;
}
}
}
上一篇:python还不能作为主要编程语言的原因:


下一篇:Swift - 列表项尾部附件点击响应(感叹号,箭头等)