Last active
August 2, 2020 07:18
-
-
Save Refsa/2dae3018fc91a70f13e9687b73ca19ef to your computer and use it in GitHub Desktop.
This file contains 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 System.Collections.Generic; | |
using System.Linq; | |
using UnityEngine; | |
public class FPSCounterIMGUI : MonoBehaviour | |
{ | |
[SerializeField] int maxFrames = 100; | |
Queue<float> avgFPS = new Queue<float>(); | |
void Update() | |
{ | |
avgFPS.Enqueue(1f / Time.deltaTime); | |
if (avgFPS.Count > maxFrames) avgFPS.Dequeue(); | |
} | |
void OnGUI() | |
{ | |
Rect rect = new Rect(Vector2.zero, new Vector2(100, 25)); | |
GUI.Label(rect, $"FPS: {avgFPS.Average().ToString("#.##")}", GUI.skin.box); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment