将脚本绑定到摄像机上就OK!
using UnityEngine;
using System.Collections;
public class CameraFPS : MonoBehaviour {
public float updateInterval = 0.5f;
private float lastInterval; // Last interval end time
private int frames = 0; // Frames over current interval
private float fps; // Current FPS
private float sum = 0.0f;
private float num = 0.0f;
// Use this for initialization
void Start()
{
lastInterval = Time.realtimeSinceStartup;
frames = 0;
}
void OnGUI()
{
GUILayout.Label("fps:" + fps.ToString("f0") + " " + (sum / num).ToString("f0"));
}
// Update is called once per frame
void Update()
{
transform.RotateAround(Vector3.zero, Vector3.up, 100 * Time.deltaTime);
++frames;
float timeNow = Time.realtimeSinceStartup;
if (timeNow > lastInterval + updateInterval)
{
fps = frames / (timeNow - lastInterval);
frames = 0;
lastInterval = timeNow;
sum += fps;
num++;
}
}
}
转载自博客 http://blog.csdn.net/goodai007/article/details/8474134