直接上脚本了:

 using UnityEngine;
using System.Collections; public class ShowFPS : MonoBehaviour {
//设置帧率
Application.targetFrameRate = ;
public float f_UpdateInterval = 0.5F; private float f_LastInterval; private int i_Frames = ; private float f_Fps; void Start()
{
//Application.targetFrameRate=60; f_LastInterval = Time.realtimeSinceStartup; i_Frames = ;
} void OnGUI()
{
GUI.Label(new Rect(, , , ), "FPS:" + f_Fps.ToString("f2"));
} void Update()
{
++i_Frames; if (Time.realtimeSinceStartup > f_LastInterval + f_UpdateInterval)
{
f_Fps = i_Frames / (Time.realtimeSinceStartup - f_LastInterval); i_Frames = ; f_LastInterval = Time.realtimeSinceStartup;
}
}
}

拿一个别人的带注释的:

以备之后用,

// 帧数计算器,需要UGUI来显示,其实可以通过写在OnGUI中显示
[RequireComponent(typeof (Text))]
public class FPSCounter : MonoBehaviour
{
const float fpsMeasurePeriod = 0.5f; //FPS测量间隔
private int m_FpsAccumulator = 0; //帧数累计的数量
private float m_FpsNextPeriod = 0; //FPS下一段的间隔
private int m_CurrentFps; //当前的帧率
const string display = "{0} FPS"; //显示的文字
private Text m_Text; //UGUI中Text组件 private void Start()
{
m_FpsNextPeriod = Time.realtimeSinceStartup + fpsMeasurePeriod; //Time.realtimeSinceStartup获取游戏开始到当前的时间,增加一个测量间隔,计算出下一次帧率计算是要在什么时候
m_Text = GetComponent<Text>();
} private void Update()
{
// 测量每一秒的平均帧率
m_FpsAccumulator++;
if (Time.realtimeSinceStartup > m_FpsNextPeriod) //当前时间超过了下一次的计算时间
{
m_CurrentFps = (int) (m_FpsAccumulator/fpsMeasurePeriod); //计算
m_FpsAccumulator = 0; //计数器归零
m_FpsNextPeriod += fpsMeasurePeriod; //在增加下一次的间隔
m_Text.text = string.Format(display, m_CurrentFps); //处理一下文字显示
}
}
}

  

Unity 显示FPS(C#语言)的更多相关文章

  1. Unity之显示fps功能

    如下: using UnityEngine; using System.Collections; public class ShowFpsOnGUI : MonoBehaviour { public ...

  2. Unity制作FPS Demo

    等到把这个Unity FPS Demo[僵尸杀手]完成后再详细补充一下,使用Unity制作FPS游戏的经历,今天做个标识.

  3. Git安装配置和提交本地代码至Github,修改GitHub上显示的项目语言

    1. 下载安装git Windows版Git下载地址: https://gitforwindows.org/ 安装没有特别要求可以一路Next即可,安装完成后可以看到: 2. 创建本地代码仓库 打开G ...

  4. 如何在Unity中显示FPS

    using UnityEngine; using System.Collections; public class example : MonoBehaviour { public float upd ...

  5. 关于Unity中FPS第一人称射击类游戏制作(专题十)

    当前Unity最新版本5.6.3f1,我使用的是5.5.1f1 场景搭建 1: 导入人物模型, 手持一把枪;2: 导入碎片模型;3: 创建一个平面;4: 创建一个障碍物;5: 导入人物模型;6: 配置 ...

  6. web国际化,在不同的浏览环境,显示不同的语言

    所谓国际化就是支持多种语言,web应用在不同的浏览环境中可以显示出不同的语言.假设我们正在开发一个支持多国语言的Web应用程序,要求系统能够根据客户端的系统的语言类型返回对应的界面:英文的操作系统返回 ...

  7. Android开发实例 Unity显示Toast

    Android中的Toast是一种简易的消息提示框. 当视图显示给用户,在应用程序中显示为浮动.和Dialog不一样的是,它永远不会获得焦点,无法被点击.用户将可能是在中间键入别的东西.Toast类的 ...

  8. arcgis显示其他国家语言

    接手一个韩国的项目,需要在arcmap中配置一个韩国地图并发布到arcserver中进行切图,给的韩国地图的shapefile文件中属性字段都是韩文的,在中文的系统中,arcMap中显示的韩文都是乱码 ...

  9. unity 显示帧率

    Game视图右上角Stats按钮按下即可显示统计信息.

随机推荐

  1. Android Studio 打包签名教程

    android studio apk第三方加固与签名,混淆打包 https://jingyan.baidu.com/article/f25ef2545386af482c1b828f.html Andr ...

  2. rabbitmq3.7.5 centos7 安装笔记

    先安装各种依赖文件: yum -y install gcc glibc-devel make ncurses-devel openssl-devel xmlto perl wget vim 1. ra ...

  3. maven依赖jar导出消失问题

      问题:maven依赖jar导出消失问题 新创新的Maven管理的项目,使用的模板是maven-archetype-quickstart,设置maven管理的jar导出时,如下 在每次”update ...

  4. 一起学Hive——总结各种Join连接的用法

    Hive支持常用的SQL join语句,例如内连接.左外连接.右外连接以及HiVe独有的map端连接.其中map端连接是用于优化Hive连接查询的一个重要技巧. 在介绍各种连接之前,先准备好表和数据. ...

  5. 【Android】application标签说明

    <application> <application android:allowClearUserData=["true" | "false" ...

  6. 【Android】Android EditText 去除边框

    [Android]Android EditText 去除边框 将EditText属性设置修改 android:background="@null" //////////////// ...

  7. Codeforces 1017E The Supersonic Rocket 凸包,计算几何,字符串,KMP

    原文链接https://www.cnblogs.com/zhouzhendong/p/CF1017E.html 题目传送门 - CF1017E 题意 给定两个点集,并构成两个凸包. 问这两个凸包是否可 ...

  8. HDU4185 Oil Skimming 二分图匹配 匈牙利算法

    原文链接http://www.cnblogs.com/zhouzhendong/p/8231146.html 题目传送门 - HDU4185 题意概括 每次恰好覆盖相邻的两个#,不能重复,求最大覆盖次 ...

  9. scrapy下载图片报[scrapy.downloadermiddlewares.robotstxt] DEBUG: Forbidden by robots.txt:错误

    本文转自:http://blog.csdn.net/zzk1995/article/details/51628205 先说结论,关闭scrapy自带的ROBOTSTXT_OBEY功能,在setting ...

  10. Linux安装Tomcat-Nginx-FastDFS-Redis-Solr-集群——【第五集之网络配置】

    还有对第五集的补充:https://www.cnblogs.com/lirenhe/p/10405069.html 1,如果不为这个linux系统或者这台虚拟机配置IP,就不能实现通信.这样的之后安装 ...