首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件开发 >

Unity3D-day03

2013-10-03 
Unity3D--day03GameObject.GetComponentGetComponent(type: Type): ComponentParameterstypeThe type of

Unity3D--day03
GameObject.GetComponentGetComponent(type: Type): Component;Parameters
typeThe type of Component to retrieve.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.

function Start () {var curTransform : Transform;curTransform = gameObject.GetComponent(Transform);// This is equivalent to:curTransform = gameObject.transform;}

function Update () {// To access public variables and functions // in another script attached to the same game object.// (ScriptName is the name of the javascript file)var other : ScriptName = gameObject.GetComponent(ScriptName);// Call the function DoSomething on the scriptother.DoSomething ();// set another variable in the other script instanceother.someVariable = 5;}GetComponent(): T;Description

Generic version. See the Generic Functions page for more details.

GetComponent(type: string): Component;Parameters
typeThe type of Component to retrieve.Description

Returns the component with name type if the game object has one attached, null if it doesn't.

返回组件名称类型如果游戏对象有一个附件,空如果它不。

function Update () {// To access public variables and functions // in another script attached to the same game object.// (ScriptName is the name of the javascript file)var other : ScriptName;other = gameObject.GetComponent("ScriptName");// Call the function DoSomething on the scriptother.DoSomething ();// set another variable in the other script instanceother.someVariable = 5;}

热点排行