Unity中FPS显示
2020-05-07 16:17 作者:unity_某某师_高锦锦 | 我要投稿
Unity中显示当前帧数
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class FPSShow : MonoBehaviour
{
public Text FPSTex;
private float time, frameCount;
private float fps = 0;
void Update()
{
if (time >= 1 && frameCount >= 1)
{
fps = frameCount / time;
time = 0;
frameCount = 0;
}
FPSTex.color = fps >= 20 ? Color.white : (fps > 15 ? Color.yellow : Color.red);
FPSTex.text = "FPS为:" + fps.ToString("f2");
time += Time.unscaledDeltaTime;
frameCount++;
}
}