UPF/Assets/Game/Scripts/FPSCounter.cs
2023-02-24 22:14:55 +05:30

31 lines
636 B
C#
Executable File

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class FPSCounter : MonoBehaviour
{
public int fps;
public TMP_Text fpsTxt;
float t;
public void Update ()
{
float current = 0;
current = (int)(1f / Time.unscaledDeltaTime);
fps = (int)current;
if(t < 0.2f){
t += Time.deltaTime;
return;
}
fpsTxt.text = fps.ToString() + " FPS";
t=0;
}
void OnValidate(){
if(fpsTxt == null){
fpsTxt = GetComponent<TMP_Text>();
}
}
}