当前位置:网站首页>Basic syntax of unity script (2) -record time in unity
Basic syntax of unity script (2) -record time in unity
2022-06-30 13:01:00 【ht_ game】
stay Unity It takes to record time in Time class .
Time The more important variables in the class are deltaTime( read-only )
deltaTime: The time taken to complete the last frame ( The interval from the last frame to the current frame ( In seconds )), That is, incremental time
Use : If you want to rotate an object evenly , Regardless of the frame rate , It can be multiplied by Time.deltaTime.
// rotate
void Update () {
this.transform.Rotate(10 * Time.deltaTime, 0, 0);
}
// Move
void Update () {
this.transform.Translate(0, 0, 10 * Time.deltaTime);// Move... Every second 10 rice
}
If you want to increase or decrease one value per second , need multiply Time.deltaTime, At the same time, it should also be clear that in the game, it takes every second 1 Units per frame 1 Effect of units . If it is multiplied by Time.deltaTime, Then the game object will follow a fixed rhythm instead of depending on the frame rate of the game , therefore , The motion of the game object becomes easier to control .
Why use Time.deltaTime?
Update() The number of frames updated per second is different , Incremental time changes in real time , And every frame changes . The incremental time guarantees that no matter what the frame rate , Can make the object move to a fixed value .
1 second 30 frame , So the frame size time is 1/30 second
1 second 180 frame , So the frame size time is 1/180 second
in general , Use Time.deltaTime The object can be moved or rotated to a specified value . such as , Move... Every second N rice
for example
public GameObject gameObject;
void Update () {
Vector3 te = gameObject.transform.position;// Get the position coordinates of the game object
te.y += 5 * Time.deltaTime;// Along the y The axis rises every second 5 A unit of
gameObject.transform.position = te;// Set the position coordinates of the game object
// This method is actually the same as MovePOSiton Method phase view
}
If rigid bodies are involved , It can be written in FixedUpdate In the method . stay FixedUpdate In the method , If you want to increase or decrease one value per second , It needs to be multiplied by Time.fixedDeltaTime.
for example
public GameObject gameObject;
void FixedUpdate()
{
Vector3 te = gameObject.GetComponent<Rigidbody>().transform.position;
te.y += 5 * Time.fixedDeltaTime;
gameObject.GetComponent<Rigidbody>().transform.position = te;
}
边栏推荐
- 【MySQL】MySQL的安装与配置
- Exploring the source code of Boca Cross Chain Communication: Elements
- Can the polardb MySQL fees for RDS MySQL data migration be transferred?
- [surprised] the download speed of Xunlei is not as fast as that of the virtual machine
- 常用的ui组件
- Flink SQL console, group not recognized_ Concat function?
- 波卡跨链通信源码探秘: 要素篇
- RK356x U-Boot研究所(命令篇)3.3 env相关命令的用法
- 2022-06-23 帆软部分公式及sql生成(月份、季度取数)
- Golang foundation -- slicing several declaration methods
猜你喜欢
![[yitianxue awk] regular matching](/img/a6/608ec8d0808dfae04d19dfeea66399.png)
[yitianxue awk] regular matching

【C语言深度解剖】float变量在内存中存储原理&&指针变量与“零值”比较

Android development interview real question advanced version (with answer analysis)

Qt读写Excel--QXlsx工作表显示/隐藏状态设置4
![[MySQL] MySQL installation and configuration](/img/82/8500949734e57e6a1047c4e838f625.png)
[MySQL] MySQL installation and configuration

排查问题的方法论(适用于任何多方合作中产生的问题排查)

Resource realization applet opening traffic main tutorial

Google refutes rumors and gives up tensorflow. It's still alive!
![[one day learning awk] Fundamentals](/img/09/a3eb03066eb063bd8594065cdce0aa.png)
[one day learning awk] Fundamentals

杭州电子商务研究院:官网(网站)是私域的唯一形态
随机推荐
RK356x U-Boot研究所(命令篇)3.2 help命令的用法
Resource realization applet opening wechat official small store tutorial
【300+精选大厂面试题持续分享】大数据运维尖刀面试题专栏(二)
Dataworks synchronizes maxcomputer to sqlserver. Chinese characters become garbled. How can I solve it
ABAP toolbox v1.0 (with implementation ideas)
数据湖(十一):Iceberg表数据组织与查询
Golang Basics - string and int, Int64 inter conversion
[one day learning awk] Fundamentals
Dark horse notes -- wrapper class, regular expression, arrays class
【OpenGL】OpenGL Examples
【C】深入理解指针、回调函数(介绍模拟qsort)
Understanding and mastery of ffmpeg avbufferpool
postman 自动生成 curl 代码片段
江西财经大学智慧江财登录分析
Rk356x u-boot Institute (command section) 3.2 usage of help command
Hangzhou E-Commerce Research Institute: the official website (website) is the only form of private domain
排查问题的方法论(适用于任何多方合作中产生的问题排查)
黑马笔记---常用日期API
微信小程序报错:TypeError: Cannot read property ‘setData‘ of undefined
golang基础 —— 切片和数组的区别