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 ...
随机推荐
- js动画之缓冲运动
缓冲运动就是运动的速度与时间或者距离有关联,不是一般的匀速运动 <!DOCTYPE html> <html lang="en"> <head> ...
- 用PowerMock mock final类constructors
也相对简单,直接贴代码 被测方法 public class EmployeeServiceWithParam { public void createEmployee(final Employee e ...
- win10 Unistack 服务组 占用资源如何解决
开始菜单>设置>隐私,隐私界面的左侧栏目,找最后一个“后台应用”,把后台运行的应用全部关掉即可
- JS 笔记(二) - 函数
1. 函数的 声明 1) 声明式写法 function j1(id){ alert(id); } 2) 声明匿名函数变量 var j2 = function (a, b) { alert(a + &q ...
- java第一天学习作业及答案
作业一 一.选择题 1.选出在java中有效的注释声明(AD)(选两项) A.//这是注释 B.*/这是注释*/ C./这是注释 D./*这是注释*/ 2.在控制台运行一个java程序,使用的命名正确 ...
- android系统自带的日期、时间对话框的用法
代码: package com.test; import java.util.Calendar; import android.app.Activity; import android.app.Dat ...
- hdu 2074
ps:WA了好多次...因为首先是n=1的情况,其次是中心花色和外花色,中心花色也有可能是最外层花色....很无语. 然后就是格式问题咯. 代码 #include "stdio.h" ...
- Java集合与算法
梗概: 集合接口 集合实现(链表.数组列表.散列集.树集.队列与双端队列.映射表) 集合与数组之间的转换 算法(排序.二分查找). 文章链接: http://mp.weixin.qq.com/s?__ ...
- 【转】Duff's Device
在看strcpy.memcpy等的实现发现用了内存对齐,每一个word拷贝一次的办法大大提高了实现效率,参加该blog(http://totoxian.iteye.com/blog/1220273). ...
- [Java coding] leetcode notes
1, 如何不排序而找到最大,次大或者最小值? var int max1, max2, min1; iterate array once: update max1, max2, min1, for ex ...