Mono显示帧率:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
/// <summary>
/// 显示帧率
/// </summary>
public class FPS : MonoBehaviour
{
public Text fpsText2;
int frames2 = 0;
float timer = 0;
// Update is called once per frame
void Update()
{
++frames2;
timer += Time.deltaTime;
if (timer >= 1)
{
timer = 0;
fpsText2.text = frames2.ToString();
frames2 = 0;
}
}
}
OnGUI显示帧率:
using UnityEngine;
using System.Collections;
/// <summary>
/// ONGUI帧显示
/// </summary>
public class FPSGUI : MonoBehaviour
{
private float currentTime = 0;
private float lateTime = 0;
private float framesNum = 0;
private float fpsTime = 0;
// Update is called once per framevoid Update
private void Update()
{
currentTime += Time.deltaTime;
framesNum++;
if (currentTime - lateTime >= 1.0f)
{
fpsTime = framesNum / (currentTime - lateTime);
lateTime = currentTime;
framesNum = 0;
}
}
void OnGUI()
{
GUI.Label(new Rect(0, 0, 100, 100), "fps : " + fpsTime.ToString());
}
}
PS:突然有个朋友问帧率怎么用OnGUI显示出来,我才发现我也忘了 XD 赶紧把这个东西补上