前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Unity3d开发_课本

Unity3d开发_课本

作者头像
用户8447427
发布2022-08-18 16:24:04
6460
发布2022-08-18 16:24:04
举报
文章被收录于专栏:userlyz学习记录userlyz学习记录

第四章游戏脚本

使用OnGUI显示FPS

显示FPS
显示FPS
代码语言:javascript
复制
public float updateInterval = 0.5f;
public int test;
private float accum = 0;
private int frames = 0;
private float timeleft;
private string stringFps;
void Start()
{
    timeleft = updateInterval;
}
void Update()
{
    timeleft -= Time.deltaTime;
    accum += Time.timeScale / Time.deltaTime;
    ++frames;
    if (timeleft <= 0.0f)
    {
        float fps = accum / frames;
        string format = System.String.Format("{0:F2} FPS", fps);
        stringFps = format;
        timeleft = updateInterval;
        accum = 0.0f;
        frames = 0;
    }
}
void OnGUI()
{
    GUIStyle guistyle = GUIStyle.none;
    guistyle.fontSize = 30;
    guistyle.normal.textColor = Color.red;
    guistyle.alignment = TextAnchor.UpperLeft;
    Rect rt = new Rect(40, 0, 100, 100);
    GUI.Label(rt, stringFps,guistyle);
}

下边的代码强制设置fps最高帧为30帧要使用int 而不能使用float类型的参数

代码语言:javascript
复制
Application.targetFrameRate=30;
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022-03-14,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 第四章游戏脚本
    • 使用OnGUI显示FPS
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档