当前位置:网站首页>Unity脚本API—Time类
Unity脚本API—Time类
2022-07-04 14:13:00 【@夜魅】
Time类:
1、从Unity获取时间信息的接口
2、常用属性:
time:从游戏开始到现在所用时间
timeScale:时间缩放
deltaTime:以秒为单位,表示每帧的经过时间
unscaledDeltaTime:不受缩放影响的每帧经过时间
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
///
/// </summary>
public class TimeDemo : MonoBehaviour
{
public int speed = 100;
public float a,b,c;
public int count;
public float du;
public int timeVsCount;
public int duVsCount;
//渲染场景时执行,不受TimeScale影响
public void Update()
{
a = Time.time;//受缩放影响的游戏运行时间
b = Time.unscaledTime;//不受缩放影响的游戏运行时间
c = Time.realtimeSinceStartup;//实际游戏运行时间
//每渲染帧 执行1次 旋转1度
//1秒 旋转?度 1秒内旋转帧数 相同的情况下
//帧多 1秒旋转速度快 希望1帧旋转量小
// 少 慢 大
this.transform.Rotate(0, speed * Time.deltaTime,0);
//游戏暂停,个别物体不受影响 Time.unscaledDeltaTime:不受缩放影响的每帧间隔
this.transform.Rotate(0, speed * Time.unscaledDeltaTime, 0);
//旋转/移动速度 * 每帧消耗时间,可以保证旋转/移动速度不受机器性能,以及渲染影响
count++;
du += speed * Time.deltaTime;
if (a >= 1 && timeVsCount < 1)
{
//speed:100 1秒渲染76次
//speed:200 1秒渲染66次
Debug.Log("游戏帧渲染了"+count+"次");
Debug.Log("游戏对象旋转了" + du + "度");
Debug.Log(Time.deltaTime);
timeVsCount++;
}
if (du >= 360 && duVsCount < 1)
{
Debug.Log("游戏对象旋转一周,共计渲染量为" + count + "次");
Debug.Log("游戏对象旋转了" + du + "度");
Debug.Log(Time.deltaTime);
duVsCount++;
}
}
//固定 0.02 秒 执行一次 与渲染无关,受TimeScale影响
public void FixedUpdate()
{
this.transform.Rotate(0,speed,0);
}
//游戏暂停
private void OnGUI()
{
if (GUILayout.Button("暂停游戏"))
{
Time.timeScale = 0;
}
if (GUILayout.Button("继续游戏"))
{
Time.timeScale = 1;
}
}
}
边栏推荐
- LeetCode 1184. 公交站间的距离 ---vector顺逆时针
- Korean AI team plagiarizes shock academia! One tutor with 51 students, or plagiarism recidivist
- When synchronized encounters this thing, there is a big hole, pay attention!
- They are all talking about Devops. Do you really understand it?
- %f格式符
- How to rapidly deploy application software under SaaS
- 2022 financial products that can be invested
- AI做题水平已超过CS博士?
- 华为云数据库DDS产品深度赋能
- Align left and right!
猜你喜欢
Ffprobe common commands
Kubernets Pod 存在 Finalizers 一直处于 Terminating 状态
深度学习 网络正则化
Leetcode 1200 minimum absolute difference [sort] the way of leetcode in heroding
How to match chords
音视频技术开发周刊 | 252
How to handle exceptions in multithreading?
开源人张亮的 17 年成长路线,热爱才能坚持
I plan to teach myself some programming and want to work as a part-time programmer. I want to ask which programmer has a simple part-time platform list and doesn't investigate the degree of the receiv
Guitar Pro 8win10 latest guitar learning / score / creation
随机推荐
[local differential privacy and random response code implementation] differential privacy code implementation series (13)
SAIC Maxus officially released its new brand "mifa", and its flagship product mifa 9 was officially unveiled!
Redis publish and subscribe
EventBridge 在 SaaS 企业集成领域的探索与实践
金额计算用 BigDecimal 就万无一失了?看看这五个坑吧~~
Align left and right!
Halcon knowledge: NCC_ Model template matching
Five minutes of machine learning every day: how to use matrix to represent the sample data of multiple characteristic variables?
Who the final say whether the product is good or not? Sonar puts forward performance indicators for analysis to help you easily judge product performance and performance
The performance of major mainstream programming languages is PK, and the results are unexpected
31年前的Beyond演唱会,是如何超清修复的?
[Dalian University of technology] information sharing of postgraduate entrance examination and re examination
Weibo and Huya advance into interest communities: different paths for peers
Cann operator: using iterators to efficiently realize tensor data cutting and blocking processing
Unity update process_ Principle of unity synergy
怎么判断外盘期货平台正规,资金安全?
Width and alignment
2022 financial products that can be invested
LeetCode 1184. 公交站间的距离 ---vector顺逆时针
进制形式