Unity3D 帧数修改

1、在edit->project setting->Quality(质量)设置里把帧数设定关闭image之后才能在代码中修改游戏运行的帧数。

2.脚本中设置:

Application.targetFrameRate = 60 (设置为 -1 表示不限定帧率)

3.界面中显示

using UnityEngine;
using System.Collections;


public class ShowFps : MonoBehaviour
{
    private float m_FPS = 0;
    public float updateInterval = 0.5F;
    private float accum = 0; // FPS accumulated over the interval
    private int frames = 0; // Frames drawn over the interval
    private float timeleft; // Left time for current interval
    private GUIStyle titleStyle2 = new GUIStyle();
    void Awake()
    {
        Application.targetFrameRate = -1;
        titleStyle2.fontSize = 20;
        titleStyle2.normal.textColor = Color.green;
    }

    // Use this for initialization
    void Start()
    {
        timeleft = updateInterval;
    }

    // Update is called once per frame
    void Update()
    {

        timeleft -= Time.deltaTime;
        accum += Time.timeScale / Time.deltaTime;
        ++frames;

        // Interval ended - update GUI text and start new interval
        if (timeleft <= 0.0)
        {
            // display two fractional digits (f2 format)
            float fps = accum / frames;            
            if (fps < 30)
                titleStyle2.normal.textColor = Color.yellow;
            else
                if (fps < 10)
                titleStyle2.normal.textColor = Color.red;
            else
                titleStyle2.normal.textColor = Color.green;

            m_FPS = fps;
            //  DebugConsole.Log(format,level);
            timeleft = updateInterval;
            accum = 0.0F;
            frames = 0;
        }
    }

    void OnGUI()
    {
        string format = System.String.Format("{0:F2} FPS", m_FPS);
        GUI.Label(new Rect(Screen.width / 2, 0, 100, 100), format, titleStyle2);
    }
}

 

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值