您的位置:首页 > 其它

摄像机围绕0.0.0点旋转并显示FPS值

2014-07-14 13:07 162 查看
将脚本绑定到摄像机上就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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: