Skip to content

Instantly share code, notes, and snippets.

@asarazan
Created June 6, 2019 22:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asarazan/b7c94ed892b46372d6da5458e895ab4c to your computer and use it in GitHub Desktop.
Save asarazan/b7c94ed892b46372d6da5458e895ab4c to your computer and use it in GitHub Desktop.
using UnityEngine;
using UnityEngine.UI;
namespace Dev
{
[RequireComponent(typeof(Text))]
public class FpsText : MonoBehaviour
{
public bool ColorCodeForTarget = true;
private Text _text;
float _deltaTime = 0.0f;
private void Awake()
{
_text = GetComponent<Text>();
}
private void Update()
{
_deltaTime += (Time.unscaledDeltaTime - _deltaTime) * 0.1f;
var fps = (int) (1.0f / _deltaTime);
_text.text = $"Fps: {fps} [{Application.targetFrameRate}]";
Color color = Color.black;
switch (Application.targetFrameRate)
{
case 30:
color = Color.red;
break;
case 60:
color = Color.green;
break;
}
_text.color = color;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment