Last active
February 24, 2025 11:00
-
-
Save gapspt/2d89faaf4863407c3e35c80dee6b1bb9 to your computer and use it in GitHub Desktop.
Quick and dirty way to count frames per second (FPS) on Unity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using UnityEngine; | |
| public class FpsCounter : MonoBehaviour | |
| { | |
| float prev = -1; | |
| float fps = 0; | |
| void Update() | |
| { | |
| var now = Time.realtimeSinceStartup; | |
| if (prev >= 0) | |
| { | |
| float fpsNow = 1 / Mathf.Max(0.001f, (now - prev)); | |
| fps += (fpsNow - fps) * 0.05f; | |
| } | |
| prev = now; | |
| if (Time.frameCount % 100 == 0) | |
| { | |
| Debug.Log("FPS: " + fps); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment