unity find game object by name code example
Example 1: how to find gameobjects in unity
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour
{
public GameObject hand;
void Example()
{
hand = GameObject.Find("Hand");
hand = GameObject.Find("/Hand");
hand = GameObject.Find("/Monster/Arm/Hand");
hand = GameObject.Find("Monster/Arm/Hand");
}
}
Example 2: unity find game object by name
foreach(GameObject fooObj in GameObject.FindGameObjectsWithTag("foo"))
{
if(fooObj.name == "bar")
{
}
}
foreach (var obje in FindObjectsOfType(typeof(GameObject)) as GameObject[])
{
if(obje.name == "obje")
{
}
}
Example 3: unity gameobject.find
GameObject obj = GameObject.Find("/Parent/Child/ChildOfChild");
Example 4: what does gameobject.find return