Files
az_tank_remake/3D/Assets/Scripts/FpsCounter.cs
2022-03-07 14:25:18 +01:00

29 lines
623 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class FpsCounter : MonoBehaviour
{
public TextMeshProUGUI fpsText;
private float pollingTime = 0.5f;
private float time;
private int frameCount;
void Update()
{
time += Time.deltaTime;
frameCount++;
if(time >= pollingTime) {
float frameRate = frameCount / time;
frameRate = Mathf.Round(frameRate * 100) / 100;
fpsText.text = frameRate.ToString() + " Fps";
time -= pollingTime;
frameCount = 0;
}
}
}