Unity中FPS顯示
2020-05-07 16:17 作者:unity_某某師_高錦錦 | 我要投稿
Unity中顯示當前幀數(shù)
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++;
? ? }
}
標簽:
Unity中FPS顯示的評論 (共 條)
