FPSTester.cs 641 B

123456789101112131415161718192021222324252627
  1. using UnityEngine;
  2. public class FPSTester : MonoBehaviour
  3. {
  4. private float fpsOutputTime;
  5. private float frameCount;
  6. private float fps;
  7. private float tempDT;
  8. private Rect fpsGuiRect = new Rect(Screen.width / 50, Screen.height / 50, 100, 100);
  9. void Update()
  10. {
  11. frameCount++;
  12. tempDT = Time.realtimeSinceStartup - fpsOutputTime;
  13. if (tempDT >= 1)
  14. {
  15. fpsOutputTime = Time.realtimeSinceStartup;
  16. fps = Mathf.FloorToInt(frameCount / tempDT);
  17. frameCount = 0;
  18. }
  19. }
  20. void OnGUI()
  21. {
  22. GUI.Label(fpsGuiRect, "FPS: " + fps);
  23. }
  24. }