转自:http://blog.csdn.net/liqiangeastsun/article/details/42102145
游戏帧率,即每秒刷新的次数,帧率太低或给人一种卡的感觉,帧率过高对机器性能要求较高, 一般帧率在 30 左右即可。
测试帧率代码:
using UnityEngine; using System.Collections; public class Test : MonoBehaviour { private float time; private float updateTime = 0.5f; private float count = 0; private int frame = 0; private float fps = 0; // Use this for initialization void Start () { time = updateTime; } // Update is called once per frame void Update () { Controller(); } private void Controller() { time -= Time.deltaTime; if (time <= 0) { time = updateTime; // 每次加上 时间比例除以每帧的事件,得到每秒的频率 count += Time.timeScale / Time.deltaTime; frame++; // 总帧数除以相加次数,得到当天帧率的平均值 fps = (float)(count / frame); } if (frame > 100) { count = 0; frame = 0; } } void OnGUI() { GUI.Label( new Rect( 50, 50, 300, 200), "FPS " + fps.ToString()); } }效果: