欢迎光临散文网 会员登陆 & 注册

Unity中FPS显示

2020-05-07 16:17 作者:unity_某某师_高锦锦  | 我要投稿

Unity中显示当前帧数


using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using UnityEngine.UI;


public class FPSShow : MonoBehaviour

{

    public Text FPSTex;

    private float time, frameCount;

    private float fps = 0;

    void Update()

    {

        if (time >= 1 && frameCount >= 1)

        {

            fps = frameCount / time;

            time = 0;

            frameCount = 0;

        }

        FPSTex.color = fps >= 20 ? Color.white : (fps > 15 ? Color.yellow : Color.red);

        FPSTex.text = "FPS为:" + fps.ToString("f2");

        time += Time.unscaledDeltaTime;

        frameCount++;

    }

}


Unity中FPS显示的评论 (共 条)

分享到微博请遵守国家法律