using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class DisPlayFPS : MonoBehaviour
{
public float updataInterval = 0.5f;
private double lastInterval;
private int frames = 0;//帧数
private float fps;
public Text text;
private void Awake()
{
//Edit->ProjectSetting->Quality-V Sync Count->Don't Sync
//设置为不同步,不然下面一行代码不起作用
Application.targetFrameRate = 45;
}
// Start is called before the first frame update
void Start()
{
lastInterval = Time.realtimeSinceStartup;
}
// Update is called once per frame
void Update()
{
frames++;
float timeNow = Time.realtimeSinceStartup;
if(timeNow>lastInterval+updataInterval)
{
fps = (float)(frames / (timeNow - lastInterval));
frames = 0;
lastInterval = timeNow;
text.text = fps.ToString();
}
}
}
Unity设置和显示FPS
于 2018-12-14 14:44:58 首次发布