当前位置:网站首页>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
边栏推荐
- Product manager professional knowledge 50 (7) - how to establish a complete set of user growth system?
- Dark horse notes -- List series collections and generics
- Derivation of Park transformation formula for motor control
- 写信宝小程序开源
- MySQL implements the division of two query results
- Unity脚本的基础语法(1)-游戏对象的常用操作
- Postman automatically generates curl code snippets
- golang基础 —— 切片和数组的区别
- Unity脚本的基础语法(5)-向量
- 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
猜你喜欢
【C语言深度解剖】float变量在内存中存储原理&&指针变量与“零值”比较
Postman automatically generates curl code snippets
App wechat payment unicloud version of uniapp payment (with source code)
MATLAB小技巧(22)矩阵分析--逐步回归
江西财经大学智慧江财登录分析
Motor control Clarke( α/β) Derivation of equal amplitude transformation
postman 自动生成 curl 代码片段
黑马笔记---List系列集合与泛型
[one day learning awk] array usage
jmeter 学习笔记
随机推荐
Js根据相同值将数组转换为二维数组
FlinkSQL自定义UDTF使用的四种方式
基于ThinkPHP5封装-tronapi-波场接口-源码无加密-可二开--附接口文档-作者详细指导-2022年6月30日08:45:27
[one day learning awk] array usage
力扣之螺旋矩阵,一起旋转起来(都能看懂)
Tronapi wave field interface PHP version - interface document attached - package based on thinkphp5 - source code without encryption - can be opened in two - detailed guidance of the author - 11:49:56
Substrate 源码追新导读: 波卡系波卡权重计算全面更新, Governance 2.0 版本的优化和调整
全面解析免费及收费SSH工具的基本特性和总结
kubeedge的核心理念
RK356x U-Boot研究所(命令篇)3.2 help命令的用法
[surprised] the download speed of Xunlei is not as fast as that of the virtual machine
Qt读写Excel--QXlsx工作表显示/隐藏状态设置4
Android development interview real question advanced version (with answer analysis)
【C】深入理解指针、回调函数(介绍模拟qsort)
Product manager professional knowledge 50 (7) - how to establish a complete set of user growth system?
rxjs Observable 两大类操作符简介
STM32 移植 RT-Thread 标准版的 FinSH 组件
独立站即web3.0,国家“十四五“规划要求企业建数字化网站!
写信宝小程序开源
项目中遇到一个有趣的事情