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;
- }
- }
- }

本文介绍了一个Unity脚本,用于实时监测并显示游戏运行时的帧率(FPS)。通过设置目标帧率和统计时间间隔,该脚本能够计算并更新实际帧率,适用于游戏性能调优和实时反馈。
1413

被折叠的 条评论
为什么被折叠?



