Unity入门操作_Time类_004
来源:互联网 发布:爆菊 知乎 编辑:程序博客网 时间:2024/06/04 00:29
Time.deltaTime 增量时间
Time.time 时间(游戏总共的时间,无论游戏是否暂停)
Time.timeScale 时间缩放
// Use this for initialization
void Start () {
}//计时器float timer = 0;// Update is called once per framevoid Update(){ timer += Time.deltaTime; if (timer >= 3) { GameObject.Instantiate(gameObject); timer = 0; }}
}
//在游戏中显示的现实时间
public class Chang : MonoBehaviour {
int h;
int m;
int s;
float time;
string result;
// Use this for initialization
void Start () {
}// Update is called once per framevoid Update () {}void OnGUI(){ GUI.Label(new Rect(0, 0, 70, 20), result); Test01();}void Test01(){ time+= Time.deltaTime; if (time>=1) { time -= 1; s++; } if (s>=60) { s = 0; h++; } if (h>=60) { h = 0; } result = string.Format("{0:00}:{1:00}:{2:00}", h, m, s); //result = h + "时" + m + "分" + s + "秒";}
}
时间缩放
public class CubeMove : MonoBehaviour {
string distanceStr = "距离:0";Vector3 startPosition;string timeText = "00:00:00";// Use this for initializationvoid Start () { startPosition = transform.position; Debug.Log("屏幕的宽度:"+Screen.width); Debug.Log("屏幕的高度:"+Screen.height);}float timer = 0;int hour = 0;int minute = 0;int second = 0;// Update is called once per framevoid Update () { timer += Time.deltaTime; if (timer>1) { second++; timer -= 1; } if (second>=60) { minute++; second = 0; } if (minute>=60) { hour++; minute = 0; } timeText = string.Format("{0:00}:{1:00}:{2:00}",hour,minute,second); transform.Translate(transform.forward * Time.deltaTime * 2);}void OnGUI(){ GUI.Label(new Rect(65, 0, 100, 60), distanceStr); GUIStyle style = new GUIStyle(); style.alignment = TextAnchor.MiddleCenter; GUI.Label(new Rect(Screen.width-100,0,100,60), timeText, style); if (GUI.Button(new Rect(0,0,60,40),"1倍速度")) { Time.timeScale = 1; } if (GUI.Button(new Rect(0, 45, 60, 40), "2倍速度")) { Time.timeScale = 2; } if (GUI.Button(new Rect(0, 90, 60, 40), "暂停")) { Time.timeScale = 0; } float distance = Vector3.Distance(startPosition,transform.position); distanceStr = "距离:"+distance; }
}
阅读全文
0 0
- Unity入门操作_Time类_004
- Unity基础5_Time类
- _Time
- Unity_脚本操作对象_004
- Unity入门操作_Input_005
- Unity入门操作_025_01
- Unity入门操作_UGUI_InputFie_026
- Unity入门操作_UGUI_Toggle_027
- Unity入门操作_UGUI_Slider_028
- Unity入门操作_UGUI_ScrollBar_029
- Unity Shader笔记20140322——half4, _Time
- Unity入门操作_Application类与切换场景 _010
- Unity 入门 Gameobject类
- Unity 入门 vector 类
- Unity 入门 Transform类
- Unity 入门 Time类
- Unity 入门 Input 类
- Unity 入门 Random类
- 程序提交时出现Time Limit Exceeded时可以改一下试试的小地方
- 1030. 完美数列(25)
- 饿了么项目---8、关于iscoll的扩展 better scroll的使用----左右菜单联动(2)
- 将PDF文件进行文件的编辑需要利用什么软件
- 强连通缩点 hdu3072
- Unity入门操作_Time类_004
- 面向对象的第一个特征:封装I
- JSjQuery parent,next,prev的使用例子
- 聊聊调度框架,K8S、Mesos、Swarm 一个都不能少
- 实现Job接口制定定时任务时,参数cronExpression的说明
- 饿了么项目---9、点击按钮显示或隐藏浮出层弹框 使用css3的过渡效果transition
- tensorflow object detection API安装
- 2017"百度之星"程序设计大赛
- 【UVA11865】比赛网络(二分+有向生成树)