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.
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.
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.
private var hand : GameObject;
function Start () {
hand =
GameObject.Find(
"/Monster/Arm/Hand");
}
function Update () {
hand.transform.Rotate(0, 100 *
Time.deltaTime, 0);
}
using UnityEngine;
using System.Collections;
public class example :
MonoBehaviour {
private GameObject hand;
void Start() {
hand =
GameObject.Find(
"/Monster/Arm/Hand");
}
void Update() {
hand.transform.Rotate(0, 100 *
Time.deltaTime, 0);
}
}
import UnityEngine
import System.Collections
class example(
MonoBehaviour):
private hand as GameObject
def
Start():
hand =
GameObject.Find('/Monster/Arm/Hand')
def
Update():
hand.transform.Rotate(0, (100 *
Time.deltaTime), 0)