using System; using TMPro; using UnityEngine; namespace NBF { public class FPSShower : MonoBehaviour { public TextMeshProUGUI TextFPS; public float updateInterval = 0.2f; // 更新间隔(秒) private float accum = 0; private int frames = 0; private float timeleft; private void Awake() { Application.targetFrameRate = 300; // 设为极高值 } public int FPS; void Update() { timeleft -= Time.deltaTime; accum += Time.timeScale / Time.deltaTime; frames++; if (timeleft <= 0.0f) { FPS = (int)(accum / frames); timeleft = updateInterval; accum = 0.0f; frames = 0; TextFPS.text = FPS.ToString(); } } } }