您的位置:首页 > 移动开发 > Unity3D

Unity3D显示帧率以及设置不限制帧率

2015-05-07 12:55 405 查看
using UnityEngine;  
    using System.Collections;  
      
    public class Fps : MonoBehaviour  
    {  
        float updateInterval = 0.5f;  
        private float accum = 0.0f;   
        private float frames = 0;   
        private float timeleft;   
        // Use this for initialization  
        void Start()  
        {  
            if (!guiText)  
            {  
                enabled = false;  
                return;  
            }  
            timeleft = updateInterval;  
        }  
      
        // Update is called once per frame  
        void Update()  
        {  
            timeleft -= Time.deltaTime;  
            accum += Time.timeScale / Time.deltaTime;  
            ++frames;  
      
            if (timeleft <= 0.0)  
            {  
                guiText.text = "" + (accum / frames).ToString("f2");  
                timeleft = updateInterval;  
                accum = 0.0f;  
                frames = 0;  
            }  
        }  
    }


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: