Global FPS
This commit is contained in:
36
Assets/Scripts/GlobalFPSText.cs
Normal file
36
Assets/Scripts/GlobalFPSText.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
[RequireComponent(typeof(TMP_Text))]
|
||||
public class GlobalFPSText : MonoBehaviour
|
||||
{
|
||||
private TMP_Text text;
|
||||
private float timer;
|
||||
private int frames;
|
||||
private float fps;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if (FindObjectsByType<GlobalFPSText>(FindObjectsSortMode.None).Length > 1)
|
||||
{
|
||||
Destroy(gameObject.transform.parent.gameObject);
|
||||
return;
|
||||
}
|
||||
DontDestroyOnLoad(transform.parent.gameObject);
|
||||
text = GetComponent<TMP_Text>();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (!BazookaManager.Instance.GetSettingShowFPS() && text.text != "") text.text = "";
|
||||
frames++;
|
||||
timer += Time.unscaledDeltaTime;
|
||||
if (timer >= 0.25f)
|
||||
{
|
||||
fps = frames / timer;
|
||||
text.text = "FPS: " + Mathf.RoundToInt(fps);
|
||||
frames = 0;
|
||||
timer = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user