Add fps and console debugger
This commit is contained in:
31
Assets/Scripts/UI/FPSDebugger.cs
Normal file
31
Assets/Scripts/UI/FPSDebugger.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class FPSDebugger : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
TextMeshProUGUI fpsText;
|
||||
|
||||
private int refreshRate = 10;
|
||||
private int frameCounter = 0;
|
||||
private float totalTime = 0;
|
||||
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (frameCounter == refreshRate)
|
||||
{
|
||||
var averageFps = 1.0 / (totalTime / refreshRate);
|
||||
fpsText.text = averageFps.ToString("F1");
|
||||
frameCounter = 0;
|
||||
totalTime = 0;
|
||||
} else
|
||||
{
|
||||
totalTime += Time.deltaTime;
|
||||
frameCounter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user