当前位置:网站首页>Basic syntax of unity script (3) - accessing game object components
Basic syntax of unity script (3) - accessing game object components
2022-06-30 13:01:00 【ht_ game】
Components belong to game objects , Because all scripts are components , So general scripts can be attached to game objects .
Common components can be obtained through simple member variables
| Components | Variable |
|---|---|
| Transform | transform |
| Renderer | renderer |
| Light | collider |
| Rigidbody | rigidbody |
| Camera | Camera( Only camera objects are valid ) |
| Animation | animation |
The components here are embodied in Property panel On , And the variable is in Script As reflected in .
stay Unity in , Components attached to game objects can be accessed through GetComponent Methods to get , It can be used in this way
Along the x The axis moves in the positive direction 1 A unit of
void Update () {
transform.Translate(1*Time.deltaTime, 0, 0);
GetComponent<Transform>().Translate(1 * Time.deltaTime, 0, 0);
}
transform It's a variable. ,Transform Is a class or script . Case differences enable developers to distinguish variables from class and script names .
It can also be passed GetComponent Method to get other scripts . for example
There is already one HelloWorld class , And there is one in the class **sayHello()** Method
void Update () {
HelloWorld helloWorld=GetComponent<HelloWorld>();// obtain HelloWorld Script script
helloWorld.sayHello();// perform sayHello Method
}
How to execute only once in a script Start and Awake in
边栏推荐
- How to solve cross domain problems
- Qt读写Excel--QXlsx工作表显示/隐藏状态设置4
- Flink SQL console, group not recognized_ Concat function?
- Unity脚本的基础语法(4)-访问其他游戏对象
- jmeter 学习笔记
- Sqlserver query code is 936 simplified Chinese GBK. Should I write 936 or GBK?
- c# 怎样能写个sql的解析器
- Three ways for flinksql to customize udaf
- Js根据相同值将数组转换为二维数组
- [one day learning awk] array usage
猜你喜欢

Shell基础入门

FlinkSQL自定义UDATF实现TopN
![[yitianxue awk] regular matching](/img/a6/608ec8d0808dfae04d19dfeea66399.png)
[yitianxue awk] regular matching

FlinkSQL自定义UDAF使用的三种方式

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

In line with the trend of media integration, Zhongke Wenge and Meishe jointly create digital intelligence media publicity
![[surprised] the download speed of Xunlei is not as fast as that of the virtual machine](/img/04/b0d23266b70c9ad6990a5203ef8ddf.png)
[surprised] the download speed of Xunlei is not as fast as that of the virtual machine

Questionnaire star questionnaire packet capturing analysis

【C】深入理解指针、回调函数(介绍模拟qsort)
![[qnx hypervisor 2.2 user manual]6.2.3 communication between guest and external](/img/ca/9065325ce8882d95fb24c82fb62abc.png)
[qnx hypervisor 2.2 user manual]6.2.3 communication between guest and external
随机推荐
An interesting thing happened in the project
Unity脚本的基础语法(3)-访问游戏对象组件
When MySQL judges that the execution condition is null, it returns 0. Correct parameter count in the call to native function 'isnull',
The spiral matrix of the force buckle rotates together (you can understand it)
Dark horse notes -- wrapper class, regular expression, arrays class
Dataworks synchronizes maxcomputer to sqlserver. Chinese characters become garbled. How can I solve it
全面解析免费及收费SSH工具的基本特性和总结
今日睡眠质量记录80分
数据湖(十一):Iceberg表数据组织与查询
jmeter 学习笔记
Package based on thinkphp5 -tronapi- wave field interface - source code without encryption - can be opened twice - interface document attached - detailed guidance of the author - June 30, 2022 08:45:2
资源变现小程序开通微信官方小商店教程
Machine learning notes - Introduction to autocorrelation and partial autocorrelation
RDS MySQL数据迁移PolarDB MySQL费用可以转过去吗?
Rk356x u-boot Institute (command section) 3.3 env related command usage
All the abnormal knowledge you want is here
Kubeedge's core philosophy
Definition of variables and assignment of variables in MySQL
Terms related to JMeter performance test and performance test passing standards
Substrate 源码追新导读: Pallet Alliance 并入主线,