You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
651 B

  1. using UnityEngine;
  2. using System.Collections;
  3. public class fpsCounter : MonoBehaviour
  4. {
  5. float deltaTime = 0.0f;
  6. void Update()
  7. {
  8. deltaTime += (Time.deltaTime - deltaTime) * 0.1f;
  9. }
  10. void OnGUI()
  11. {
  12. int w = Screen.width, h = Screen.height;
  13. GUIStyle style = new GUIStyle();
  14. Rect rect = new Rect(0, 0, w, h * 2 / 100);
  15. style.alignment = TextAnchor.UpperLeft;
  16. style.fontSize = h * 2 / 100;
  17. style.normal.textColor = new Color (0.0f, 0.0f, 0.5f, 1.0f);
  18. float msec = deltaTime * 1000.0f;
  19. float fps = 1.0f / deltaTime;
  20. string text = string.Format("{0:0.0} ms ({1:0.} fps)", msec, fps);
  21. GUI.Label(rect, text, style);
  22. }
  23. }