显示FPS

using System.Collections;
using UnityEngine;

public class ShowFPS : MonoBehaviour
{
    [Header("OnGUI for frame rate---")]
    public Color textColor = Color.white;
    public int guiFontSize = 50;
    private string label = string.Empty;
    private GUIStyle style = new GUIStyle();
    private float count;

    private void Awake()
    {
        // set target frame rate
        Application.targetFrameRate = 60;
    }

    private IEnumerator Start()
    {
        while (true)
        {
            count = 1f / Time.deltaTime;
            label = string.Format("当前FPS:{0:N2}", count);
            yield return new WaitForSeconds(0.2f);

        }
    }
    // show fps
    private void OnGUI()
    {
        style.fontSize = guiFontSize;
        style.normal.textColor = textColor;
        GUI.Label(new Rect(300f, 200f, 500f, 300f), this.label, this.style);
    }
}

猜你喜欢

转载自blog.csdn.net/Mediary/article/details/88524730
FPS