Unity3D-day03
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;}