当前位置:网站首页>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
- 机器学习笔记 - 自相关和偏自相关简介
- 电机控制Clarke(α/β)等幅值变换推导
- Rk356x u-boot Institute (command section) 3.2 usage of help command
- MySQL judges the calculation result and divides it by 100
- Machine learning notes - Introduction to autocorrelation and partial autocorrelation
- c# 怎样能写个sql的解析器
- 基于ThinkPHP5封装-tronapi-波场接口-源码无加密-可二开--附接口文档-作者详细指导-2022年6月30日08:45:27
- 你想要的异常知识点都在这里了
- 独立站即web3.0,国家“十四五“规划要求企业建数字化网站!
猜你喜欢

App wechat payment unicloud version of uniapp payment (with source code)

黑马笔记---常用日期API

In line with the trend of media integration, Zhongke Wenge and Meishe jointly create digital intelligence media publicity

【驚了】迅雷下載速度竟然比不上虛擬機中的下載速度

Shell编程概述

WTM重大更新,多租户和单点登录

FlinkSQL自定义UDATF实现TopN

Determining the subject area of data warehouse construction
![[300+ continuous sharing of selected interview questions from large manufacturers] column on interview questions of big data operation and maintenance (II)](/img/cf/44b3983dd5d5f7b92d90d918215908.png)
[300+ continuous sharing of selected interview questions from large manufacturers] column on interview questions of big data operation and maintenance (II)

【C】深入理解指针、回调函数(介绍模拟qsort)
随机推荐
Substrate 源码追新导读: 质押额度大幅度削减, RocksDB可以完全被Disable
FlinkSQL自定义UDAF使用的三种方式
JMeter's performance test process and performance test focus
Unity脚本的基础语法(5)-向量
Rk356x u-boot Institute (command section) 3.2 usage of help command
Determining the subject area of data warehouse construction
Common UI components
全面解析免费及收费SSH工具的基本特性和总结
Qt中的数据库使用
Introduction to the renewal of substrate source code: the pledge amount is greatly reduced, and rocksdb can be completely disabled
LeetCode_栈_中等_227.基本计算器 II(不含括号)
Hangzhou E-Commerce Research Institute: the official website (website) is the only form of private domain
Apple executives openly "open the connection": Samsung copied the iPhone and only added a large screen
Product manager professional knowledge 50 (7) - how to establish a complete set of user growth system?
Qt中的事件处理
【 surprise】 la vitesse de téléchargement de Thunderbolt n'est pas aussi rapide que celle de la machine virtuelle
After the market value evaporated by 65billion yuan, the "mask king" made steady medical treatment and focused on condoms
Terms related to JMeter performance test and performance test passing standards
Illustration creating a stored procedure using Navicat for MySQL
项目中遇到一个有趣的事情