unity获取脚本组件_GameObject.GetComponent 获取组件

本文介绍了Unity中获取游戏对象组件的关键方法GetComponent,包括如何通过Type和字符串来访问内置组件或脚本组件。示例代码展示了在Start和Update函数中如何使用GetComponent来获取并操作Transform和自定义脚本组件。
摘要由CSDN通过智能技术生成

GameObject.GetComponent 获取组件

function GetComponent (type : Type) : Component

Description描述

Returns the component of Type type if the game object has one attached, null if it doesn't. You can access both builtin components or scripts with this function.

如果这个游戏物体包含一个类型为type的组件,则返回它。如果没有则为空。通过这个函数,你可以访问内建的组件或者脚本的组件。

GetComponent is the primary way of accessing other components. From javascript the type of a script is always the name of the script as seen in the project view.

GetComponent是访问别的组件的原始方法,对javascript来说,脚本的类型就是项目视图里面看到的脚本名称。

using UnityEngine;

using System.Collections;

public class example : MonoBehaviour {

void Start() {

Transform curTransform;

curTransform = gameObject.GetComponent();

curTransform = gameObject.transform;

}

void Update() {

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值