Skip to content

Instantly share code, notes, and snippets.

@Refsa
Last active August 2, 2020 07:18
Show Gist options
  • Save Refsa/2dae3018fc91a70f13e9687b73ca19ef to your computer and use it in GitHub Desktop.
Save Refsa/2dae3018fc91a70f13e9687b73ca19ef to your computer and use it in GitHub Desktop.
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