Created
June 6, 2019 22:30
-
-
Save asarazan/b7c94ed892b46372d6da5458e895ab4c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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