using UnityEngine;
using UnityEngine.UI;

public class FPSDisplayer : MonoBehaviour
{
    [SerializeField]
    private Text _text;
    [SerializeField]
    private float _updateInterval = 0.2f;

    private float deltaTime = 0.0f;
    private float _time;

    void Update()
    {
        deltaTime += (Time.unscaledDeltaTime - deltaTime) * 0.1f;

        //float fps = (int)(1f / Time.unscaledDeltaTime);

        _time += Time.deltaTime;
        if (_time > _updateInterval)
        {
            _time = 0;
            var msec = deltaTime * 1000.0f;
            var fps = 1.0f / deltaTime;
            string s = $"{msec:0.0} ms ({fps:0.} fps)";
            //_text.text = ((int)fps).ToString() + " FPS";
            _text.text = s;
        }
    }
}
