UNITY5以后怎么改GUI文字
提要:以前是UNITY4,后来用了新的UI,于是GUIText这种东西就没有了,研究了很久。。。。
----------------------------
这里我想拖个GUI文字框显示FPS,于是代码是这样,这段代码是我在UNITY官方BBS找到并修改的,感谢原作者分享
using UnityEngine;
using System.Collections;
using UnityEngine.UI; //引用里加入这个 public class getFPS : MonoBehaviour {
// Use this for initialization // Attach this to a GUIText to make a frames/second indicator.
//
// It calculates frames/second over each updateInterval,
// so the display does not keep changing wildly.
//
// It is also fairly accurate at very low FPS counts (<10).
// We do this not by simply counting frames per interval, but
// by accumulating FPS for each frame. This way we end up with
// correct overall FPS even if the interval renders something like
// 5.5 frames. public float updateInterval = 0.5F; private float accum = ; // FPS accumulated over the interval
private int frames = ; // Frames drawn over the interval
private float timeleft; // Left time for current interval void Start()
{ if (!GetComponent<Text>())
{
Debug.Log("这个组建需要加载在新UI的Text上");
enabled = false;
return;
}
timeleft = updateInterval;
} 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;
string format = System.String.Format("{0:F2} FPS", fps);
GetComponent<Text>().text = format; if (fps < )
GetComponent<Text>().material.color = Color.yellow;
else
if (fps < )
GetComponent<Text>().material.color = Color.red;
else
GetComponent<Text>().material.color = Color.green;
// DebugConsole.Log(format,level);
timeleft = updateInterval;
accum = 0.0F;
frames = ;
}
} }
UNITY5以后怎么改GUI文字的更多相关文章
- UITextField-修改占位文字和光标的颜色,大小
一.设置占位文字的颜色 方法一:利用富文本 /** 手机号输入框 */ @property (weak, nonatomic) IBOutlet UITextField *phoneTextField ...
- ios_UITextField-修改占位文字和光标的颜色,大小
一.设置占位文字的颜色 方法一:利用富文本 /** 手机号输入框 */ @property (weak, nonatomic) IBOutlet UITextField *phoneTextField ...
- ionic改tab文字和icon图片的颜色
The official way would be: Change in your theme/variables.scss Active icon for tabs on android is: $ ...
- C# 使用 GDI+ 实现添加中心旋转(任意角度)的文字
这篇文章是 GDI+ 总结系列的第三篇,如果对 GDI+ 的基础使用不熟悉的朋友可以先看第一篇文章<C# 使用 GDI+ 画图>. 需求 需求是要实现给图片添加任意角度旋转的文字,文字的旋 ...
- Oracle调优总结(经典实践 重要)
转载:http://langgufu.iteye.com/blog/1974211 Problem Description:1.每个表的结构及主键索引情况2.每个表的count(*)记录是多少3.对于 ...
- 大型系统开发sql优化总结(转)
Problem Description: 1.每个表的结构及主键索引情况 2.每个表的count(*)记录是多少 3.对于创建索引的列,索引的类型是什么?count(distinct indexcol ...
- Linux 桌面玩家指南:01. 玩转 Linux 系统的方法论
特别说明:要在我的随笔后写评论的小伙伴们请注意了,我的博客开启了 MathJax 数学公式支持,MathJax 使用$标记数学公式的开始和结束.如果某条评论中出现了两个$,MathJax 会将两个$之 ...
- Linux系统的方法论
Linux系统的方法论 https://www.cnblogs.com/youxia/p/LinuxDesktop001.html 阅读目录 特别说明 什么情况下适合玩Linux桌面 Linux桌面系 ...
- call to OpenGL ES API with no current context 和Fatal signal 11
近日在用cocos2dx3.4的时候使用了JNI调用,发现一个现象 当不使用jni的时候全然正常.使用了jni后回去的全部文字都变成黑块,而且有概率程序崩溃.附带出了两个log call to Ope ...
随机推荐
- Scala编程--基本类型和操作
如果你熟悉Java,你会很开心地发现Java基本类型和操作符在Scala里有同样的意思.然而即使你是一位资深Java开发者,这里也仍然有一些有趣的差别使得本章值得一读.因为本章提到的一些Scala的方 ...
- NPOI 2.0 读取、编辑、保存Excel文件
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.I ...
- SSH整合开发的web.xml配置
<?xml version="1.0" encoding="UTF-8"?><web-app version="2.5" ...
- http状态消息
1-5状态码了解 1XX 表示信息(消息) 2XX 表示成功 3XX 表示重定向 4XX 表示请求错误 *** 5XX 表示服务端错误 常见状态码 200 请求成功 一切正常 301 重定向,修改后的 ...
- js控制select下拉列表数据绑定
JS代码部分: <script type="text/javascript"> $(document).ready(function () { $("sel ...
- UI数据库
一.数据库 SQL: SQL是Structured Query Language(结构化查询语言)的缩写.SQL是专为数据库而建立的操作命令集, 是一种功能齐全的数据库语言. 二.数据库管理系统 数据 ...
- canvas标签(1)--线条、矩形、圆形、文本、阴影、抛小球
从网上扒拉的代码,敲了敲代码玩. html页面显示内容很简单,只要写个canvas标签,给他一个id写js就可以了 <!DOCTYPE html> <html> <hea ...
- 《Java应用程序(Application)》
在编写Java应用程序(Application)时可以这样: 1,定义包名. 2, 导入相关的包. 3, 定义一个类. 4,定义相关变量. 5,定义构造函数.(在构造函数内调用init()方法和add ...
- Hadoop安装——如何修改端口冲突
在一个集群中,尽管是多用户,但是端口是公用的,存在冲突的可能.如果另一个用户已经采用默认配置安装了hadoop,那么当前用户再安装hadoop时,必然会产生端口的冲突.在配置自己的hadoop时,可以 ...
- Android添加代码检查权限
1,首先创建一个项目,然后创建一个类,hello.java public class hello { public static final String PERMISSION_SAY_HELLO = ...