代码
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
public class Frame : MonoBehaviour
{
    
    private int _frame;
    
    private float _lastTime;
    
    private float _frameDeltaTime;
    
    private float _Fps;
    private const float _timeInterval = 0.5f;
    void Start()
    {
        _lastTime = Time.realtimeSinceStartup;
    }
    void Update()
    {
        FrameCalculate();
    }
    private void FrameCalculate()
    {
        _frame++;
        if (Time.realtimeSinceStartup - _lastTime < _timeInterval)
        {
            return;
        }
        float time = Time.realtimeSinceStartup - _lastTime;
        _Fps = _frame / time;
        _frameDeltaTime = time / _frame;
        _lastTime = Time.realtimeSinceStartup;
        _frame = 0;
    }
    private void OnGUI()
    {
        string msg = string.Format("<color=red><size=30>FPS:{0}   ms:{1}</size></color>",(int) _Fps , (int)(_frameDeltaTime *1000));
        GUI.Label(new Rect(Screen.width-230, 0, 500, 150), msg);
        var timeNow = System.DateTime.Now;
        string time = string.Format("<color=green><size=30>{0}</size></color>", timeNow);
        GUI.Label(new Rect(Screen.width/2-200, 2, 600, 50), time);
    }
}
 
将脚本挂载到相机上面
 

 
效果
 
