FpsCounter.cs 670 Bytes
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class FpsCounter : MonoBehaviour
{
    private float _deltaTime = 0.0f;
    private Text _uiTxt;

    private void Start()
    {
        _uiTxt = GetComponent<Text>();
    }

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

        if (_uiTxt)
            _uiTxt.text = GetFps();
    }

    public string GetFps()
    {
        float msec = _deltaTime * 1000.0f;
        float fps = 1.0f / _deltaTime;
        string text = string.Format("{0:0.0} ms ({1:0.} fps)", msec, fps);

        return text;
    }
}