FPSCounter.js 741 B

12345678910111213141516171819202122232425262728293031323334353637
  1. var updateInterval = 0.5;
  2. var x_location = 5;
  3. var y_location = 5;
  4. private var lastInterval : double; // Last interval end time
  5. private var frames = 0; // Frames over current interval
  6. private var fps : float; // Current FPS
  7. function Awake () {
  8. useGUILayout = false;
  9. }
  10. function OnGUI () {
  11. GUI.Label (Rect(Screen.width-x_location, Screen.height- y_location, 100, 30), "FPS: " + fps.ToString("f2"));
  12. }
  13. function Start()
  14. {
  15. lastInterval = Time.realtimeSinceStartup;
  16. frames = 0;
  17. }
  18. function Update()
  19. {
  20. ++frames;
  21. var timeNow = Time.realtimeSinceStartup;
  22. if( timeNow > lastInterval + updateInterval )
  23. {
  24. fps = frames / (timeNow - lastInterval);
  25. frames = 0;
  26. lastInterval = timeNow;
  27. }
  28. }