Advertisement
Dieton

FPS-Counter

May 18th, 2023
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.61 KB | Gaming | 0 0
  1. /*
  2. By: Nathan Rumsey
  3. Engineer 3d llc
  4. 2022
  5. */
  6. using System.Collections;
  7. using System.Collections.Generic;
  8. using UnityEngine;
  9. using UnityEngine.UI;
  10. using TMPro;
  11.  
  12. public class FPS-Counter : MonoBehaviour
  13. {
  14.     [SerializeField] private TMP_Text _fpsText;
  15.     [SerializeField] private float _hudRefreshRate = 1f;
  16.     private float _timer;
  17.  
  18.     private void Update()
  19.     {
  20.         if (Time.unscaledTime > _timer)
  21.         {
  22.             int fps = (int)(1f / Time.unscaledDeltaTime);
  23.             _fpsText.text = "FPS: " + fps;
  24.             _timer = Time.unscaledTime + _hudRefreshRate;
  25.         }
  26.     }
  27. }
  28.  
Tags: Unity
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement