当前位置:网站首页>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;
}
边栏推荐
- The spiral matrix of the force buckle rotates together (you can understand it)
- 2022-06-23 帆软部分公式及sql生成(月份、季度取数)
- Hangzhou E-Commerce Research Institute: the official website (website) is the only form of private domain
- 基于ThinkPHP5封装tronapi-波场接口-PHP版本--附接口文档-20220627
- 电机控制park变换公式推导
- Rk356x u-boot Institute (command section) 3.2 usage of help command
- 微信小程序报错:TypeError: Cannot read property ‘setData‘ of undefined
- c# 怎样能写个sql的解析器
- 【MySQL】MySQL的安装与配置
- 【招聘(广州)】成功易(广州).Net Core中高级开发工程师
猜你喜欢

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

Machine learning notes - Introduction to autocorrelation and partial autocorrelation

Postman génère automatiquement des fragments de code Curl

Dark horse notes -- wrapper class, regular expression, arrays class

uniapp支付之APP微信支付unicloud版(附源码)

Google refutes rumors and gives up tensorflow. It's still alive!

今日睡眠质量记录80分

Analysis of smart jiangcai login in Jiangxi University of Finance and Economics

江西财经大学智慧江财登录分析
![[learn awk in one day] operator](/img/52/fd476d95202f3a956fd59437c2d960.png)
[learn awk in one day] operator
随机推荐
资源变现小程序开通流量主教程
杭州电子商务研究院:官网(网站)是私域的唯一形态
[surprised] the download speed of Xunlei is not as fast as that of the virtual machine
深度长文探讨Join运算的简化和提速
Android development interview real question advanced version (with answer analysis)
Substrate 源码追新导读: 修复BEEFY的gossip引擎内存泄漏问题, 智能合约删除队列优化
Unity脚本的基础语法(4)-访问其他游戏对象
一次 Keepalived 高可用的事故,让我重学了一遍它!
电机控制park变换公式推导
Introduction to the renewal of substrate source code: the pledge amount is greatly reduced, and rocksdb can be completely disabled
Dark horse notes - collection (common methods and traversal methods of collection)
Google refutes rumors and gives up tensorflow. It's still alive!
Introduction to the novelty of substrate source code: comprehensive update of Boca system Boca weight calculation, optimization and adjustment of governance version 2.0
In line with the trend of media integration, Zhongke Wenge and Meishe jointly create digital intelligence media publicity
Dark horse notes - common date API
Dark horse notes -- List series collections and generics
kaniko官方文档 - Build Images In Kubernetes
微信小程序报错:TypeError: Cannot read property ‘setData‘ of undefined
Three ways for flinksql to customize udaf
ERROR: Cannot uninstall ‘PyYAML‘. It is a distutils installed project and thus we cannot accurately