Unity3D--day03
2013-10-02 21:34
316 查看
GameObject.GetComponent
GetComponent(type: Type): Component;
Parameters
Description
Returns the component of Type
access both builtin components or scripts with this function.
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. Example:
GetComponent的主要方式是访问其他组件。从javascript脚本的类型总是脚本的名称作为项目视图中看到。示例:
// 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 script
other.DoSomething ();
// set another variable in the other script instance
other.someVariable = 5;
}
GetComponent(): T;
Description
Generic version. See the Generic Functions page
for more details.
GetComponent(type: string): Component;
Parameters
Description
Returns the component with name
返回组件名称类型如果游戏对象有一个附件,空如果它不。
It is better to use GetComponent with a Type instead of a string for performance reasons. Sometimes you might not be able to get to the type however, for example when trying to access a C# script from Javascript. In that case you can
simply access the component by name instead of type. Example:
最好是使用GetComponent类型而不是一个字符串由于性能的原因。有时候你可能无法到达类型然而,例如当试图访问一个c#脚本从Javascript。在这种情况下你可以直接访问组件的名字相反的类型。示例:
GetComponent(type: Type): Component;
Parameters
type | The type of Component to retrieve. |
Returns the component of Type
typeif the game object has one attached, null if it doesn't. You can
access both builtin components or scripts with this function.
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. Example:
GetComponent的主要方式是访问其他组件。从javascript脚本的类型总是脚本的名称作为项目视图中看到。示例:
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 script
other.DoSomething ();
// set another variable in the other script instance
other.someVariable = 5;
}
GetComponent(): T;
Description
Generic version. See the Generic Functions page
for more details.
GetComponent(type: string): Component;
Parameters
type | The type of Component to retrieve. |
Returns the component with name
typeif the game object has one attached, null if it doesn't.
返回组件名称类型如果游戏对象有一个附件,空如果它不。
It is better to use GetComponent with a Type instead of a string for performance reasons. Sometimes you might not be able to get to the type however, for example when trying to access a C# script from Javascript. In that case you can
simply access the component by name instead of type. Example:
最好是使用GetComponent类型而不是一个字符串由于性能的原因。有时候你可能无法到达类型然而,例如当试图访问一个c#脚本从Javascript。在这种情况下你可以直接访问组件的名字相反的类型。示例:
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 script other.DoSomething (); // set another variable in the other script instance other.someVariable = 5; }
相关文章推荐
- 在unity3d里,简易又快速的让物体进入Screen
- Unity3D Update() 和 FixedUpdate()区别--unity3Dday02
- Unity3D 游戏开发day01
- Unity性能优化之Draw Call
- Unity3D开发性能优化
- Unity3D开发(二):NGUI之UIButton"禁用"状态时置灰
- 使用PS3手柄在PC玩Unity3D游戏
- Unity3d Shader开发(三)Pass(Pass Tags,Name,BindChannels )
- 3.使用Unity 创建自己的android AR 项目 (小白篇)
- 2.关于Unity -Vuforia -Android 开发 ,平台的搭建(极品菜鸟完整版) 续
- [Unity3D]调用Android接口
- unity 不同版本安装
- unity IEnumerator 协同程序
- 1.关于Unity -Vuforia -Android 开发 ,平台的搭建(极品菜鸟完整版)
- Unity 跑酷Demo难题总结
- (番外篇) 高通 AR Unity 虚拟按钮 -源于 官网
- Unity3d Shader开发(三)Pass(Blending )
- unityGUI下拉菜单实现代码
- Unity3d Shader开发(三)Pass(Alpha testing )
- Unity3d Shader开发(三)Pass(Fog )