| 123456789101112131415161718192021222324252627 |
- using UnityEngine;
- public class FPSTester : MonoBehaviour
- {
- private float fpsOutputTime;
- private float frameCount;
- private float fps;
- private float tempDT;
- private Rect fpsGuiRect = new Rect(Screen.width / 50, Screen.height / 50, 100, 100);
- void Update()
- {
- frameCount++;
- tempDT = Time.realtimeSinceStartup - fpsOutputTime;
- if (tempDT >= 1)
- {
- fpsOutputTime = Time.realtimeSinceStartup;
- fps = Mathf.FloorToInt(frameCount / tempDT);
- frameCount = 0;
- }
- }
- void OnGUI()
- {
- GUI.Label(fpsGuiRect, "FPS: " + fps);
- }
- }
|