find with name unity 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 gameobject by name
GameObject enemy = GameObject.Find("enemy");
Example 3: 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 4: what does gameobject.find return