游戏中,显示FPS
游戏 stats可以显示,但是打包运行无法查看,所以我们可以手动计算FPS
FPS= 1/当前帧所花时间
编辑器新建一个 UI.Text
添加以下C#脚本
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class fpsScript : MonoBehaviour {
public float m_time;
public Text text;
public float delay=0.0f;
public int m_count=0;
// Use this for initialization
void Start () {
Application.targetFrameRate=-1;//set fps of render -1 is max
m_time = 0.0f;
text= GameObject.Find ("text_fps") .GetComponent<Text>();
}
// Update is called once per frame
void Update () {
m_count++;
if (m_count > 60) {
text.text = "FPS:"+ ((int)(1 / delay)).ToString ();
m_count=0;
}
delay = Time.realtimeSinceStartup - m_time;
m_time = Time.realtimeSinceStartup;
}
}