1. using UnityEngine;
    2. using UnityEngine.UI;
    3. public class FpsToShow : MonoBehaviour
    4. {
    5. private float fpsByDeltatime=1.5f;
    6. private float passedTime=0.0f;
    7. private int frameCount;
    8. private float realFPS=0.0f;
    9. void Update()
    10. {
    11. GetFPS();
    12. }
    13. private void GetFPS()
    14. {
    15. frameCount++;
    16. passedTime += Time.deltaTime;
    17. if (passedTime>=fpsByDeltatime)
    18. {
    19. realFPS = frameCount / passedTime;
    20. this.GetComponent<Text>().text = "FPS:" + string.Format("{0:F2}",realFPS);
    21. frameCount = 0;
    22. passedTime = 0.0f;
    23. }
    24. }
    25. }