GameObject.Find 查找
2013-11-26 16:39
274 查看
http://game.ceeger.com/Script/GameObject/GameObject.Find.html
static function Find (name : string) : GameObject
Description描述
Finds a game object by name and returns it.
If no game object with name can be found, null is returned. If name contains a '/' character it will traverse the hierarchy like a path name. This function only returns active gameobjects.
找到并返回一个名字为name的游戏物体。
如果以name为名字的游戏物体没有被找到,则返回空.如果name中包含'/'字符,这个名称将被视作一个hierarchy中的路径名.这个函数只返回活动的游戏物体。
For performance reasons it is recommended to not use this function every frame Instead cache the result in a member variable at startup or use GameObject.FindWithTag.
除非迫不得已,建议不要在每一帧中使用这个函数。可以在开始的时候用一个成员变量来缓存结果或者使用GameObject.FindWithTag函数。
C#
JavaScript
This function is most useful to automatically connect references to other objects at load time, eg. inside MonoBehaviour.Awake or MonoBehaviour.Start. You should avoid calling this function every frame eg. MonoBehaviour.Update for performance reasons. A common
pattern is to assign a game object to a variable inside MonoBehaviour.Start. And use the variable in MonoBehaviour.Update.
这个函数多用于在加载时自动连接其他物体.比如在MonoBehaviour函数中或者在MonoBehaviour.Start中使用.你应该避免在每一帧中使用这个函数,比如在MonoBehaviour.Update中使用.一个通用模式是在MonoBehaviour.Start中用一个变量来保存一个游戏物体,然后在MonoBehaviour.Updata中使用它.
C#
JavaScript
static function Find (name : string) : GameObject
Description描述
Finds a game object by name and returns it.
If no game object with name can be found, null is returned. If name contains a '/' character it will traverse the hierarchy like a path name. This function only returns active gameobjects.
找到并返回一个名字为name的游戏物体。
如果以name为名字的游戏物体没有被找到,则返回空.如果name中包含'/'字符,这个名称将被视作一个hierarchy中的路径名.这个函数只返回活动的游戏物体。
For performance reasons it is recommended to not use this function every frame Instead cache the result in a member variable at startup or use GameObject.FindWithTag.
除非迫不得已,建议不要在每一帧中使用这个函数。可以在开始的时候用一个成员变量来缓存结果或者使用GameObject.FindWithTag函数。
C#
JavaScript
var hand : GameObject; // This will return the game object named Hand in the scene. //这将返回名为Hand 的游戏物体 hand = GameObject.Find("Hand"); // This will return the game object named Hand. // Hand may not have a parent in the hierarchy view! //这将返回名为Hand 的游戏物体,在层次视图中hand也没有父级物体 hand = GameObject.Find("/Hand"); // This will return the game object named Hand, // which is a child of Arm -> Monster. // Monster may not have a parent in the hierarchy view! //这将返回Monster/Arm 的子级下名为Hand 的游戏物体,在层次视图中Monster也没有父级物体 hand = GameObject.Find("/Monster/Arm/Hand"); // This will return the game object named Hand, // which is a child of Arm -> Monster. // Monster may have a parent. //这将返回Monster/Arm 的子级下名为Hand 的游戏物体,在层次视图中Monster可以有父级物体 hand = GameObject.Find("Monster/Arm/Hand");
This function is most useful to automatically connect references to other objects at load time, eg. inside MonoBehaviour.Awake or MonoBehaviour.Start. You should avoid calling this function every frame eg. MonoBehaviour.Update for performance reasons. A common
pattern is to assign a game object to a variable inside MonoBehaviour.Start. And use the variable in MonoBehaviour.Update.
这个函数多用于在加载时自动连接其他物体.比如在MonoBehaviour函数中或者在MonoBehaviour.Start中使用.你应该避免在每一帧中使用这个函数,比如在MonoBehaviour.Update中使用.一个通用模式是在MonoBehaviour.Start中用一个变量来保存一个游戏物体,然后在MonoBehaviour.Updata中使用它.
C#
JavaScript
// Find the hand inside Start and rotate it every frame //在Start里查找hand物体,并在每帧旋转它 private var hand : GameObject; function Start () { hand = GameObject.Find("/Monster/Arm/Hand"); } function Update () { hand.transform.Rotate(0, 100 * Time.deltaTime, 0); }
相关文章推荐
- 采用GameObject.Find查找物体的子物体,并让其显示出来。
- GameObject.FindGameObjectsWithTag 通过标签查找游戏对象列表
- GameObject.Find()、Transform.Find查找游戏对象
- 【Unity3D游戏开发】GameObject.Find()、Transform.Find查找隐藏对象 (十)
- GameObject.Find()、Transform.Find查找游戏对象
- GameObject.Find()、Transform.Find查找游戏对象
- 【Unity3D游戏开发】GameObject.Find()、Transform.Find查找隐藏对象
- unity3D中GameObject.Find()、Transform.Find查找隐藏对象分析
- unity3d 查找GameObject对象,FindObjectsOfType和FindObjectOfType 之遍历
- 【unity】GameObject.Find 的性能开销分析
- Unity中使用GameObject.Find、Transform.Find查找GameObject
- GameObject.Find("/Canvas")
- GameObject.FindGameObjectsOfType
- Unity3d的GameObject.Find()的一些使用心得体会
- GameObject.Find和Transform.Find以及Transform.FindChild的区别
- 【翻译】Unity开发者们,不要再用GameObject.Find方法了!
- GameObject.Find
- unity3d GameObject.Find 严格区分大小写的
- 【Unity游戏开发之四】GameObject.Find()、Transform.Find查找隐藏对象
- 关于Unity GameObject.Find()、transform.Find()、transform.GetChild()的效率问题