码迷,mamicode.com
首页 > 编程语言 > 详细

如何在Unity中显示FPS

时间:2016-04-12 13:00:48      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:

using UnityEngine;
using System.Collections;
  
public class example : MonoBehaviour
{
    public float updateInterval = 0.5F;
    private double lastInterval;
    private int frames = 0;
    private float fps;
    void Start()
    {
        lastInterval = Time.realtimeSinceStartup;
        frames = 0;
    }
    void OnGUI()
    {
        GUILayout.Label(" " + fps.ToString("f2"));
    }
    void Update()
    {
        ++frames;
        float timeNow = Time.realtimeSinceStartup;
        if (timeNow > lastInterval + updateInterval)
        {
            fps = (float)(frames / (timeNow - lastInterval));
            frames = 0;
            lastInterval = timeNow;
        }
    }
}

 

如何在Unity中显示FPS

标签:

原文地址:http://www.cnblogs.com/dj1232090/p/5382136.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!