Application.targetFrameRate:重点=-1是默认显示
- public class FPSTest : MonoBehaviour {
- public float timeCount = 1f; //更新帧显示帧数的时间
- public int defaultFPS = 30; //默认帧频
- private float time = 0;
- private int frameCount=0;//每次统计时间之间运行多少针
- private float currentlFPS;//实际帧数
- public UILabel label;
- void Awake(){
- }
- void Start () {
- Application.targetFrameRate = defaultFPS; //设置帧率
- }
- void Update () { //实时显示帧率
- frameCount++;
- time += Time.deltaTime;
- if(time >= timeCount){
- currentlFPS = frameCount/time;
- label.text = ((int)currentlFPS).ToString();//NGUI label显示 去除小数点
- frameCount = 0;
- time = 0;
- }
- }
- }