Gameobject.find Unity Code Example


Example 1: how to find gameobjects in unity


using UnityEngine;
using System.Collections;
// This returns the GameObject named Hand in one of the Scenes.
public class ExampleClass : MonoBehaviour
{
public GameObject hand;

void Example()
{
// This returns the GameObject named Hand.
hand = GameObject.Find("Hand");

// This returns the GameObject named Hand.
// Hand must not have a parent in the Hierarchy view.
hand = GameObject.Find("/Hand");

// This returns the GameObject named Hand,
// which is a child of Arm > Monster.
// Monster must not have a parent in the Hierarchy view.
hand = GameObject.Find("/Monster/Arm/Hand");

// This returns the GameObject named Hand,
// which is a child of Arm > Monster.
hand = GameObject.Find("Monster/Arm/Hand");
}
}

Example 2: how to find a gameobject in unity


public GameObject Object //This gives you a GameObject you can attach an object to

void Start()
{
(Object) = GameObject.Find("(Objects Name)");//You put in the GameObjects name here
//or
(Object) = GameObject.FindWithTag("(Objects tag)");//You put in the GameObjects tag here
//for multiple game objects
(Object) = GameObject.FindGameObjectsWithTag("(Objects tag)");//Make multiple gameobjects with the same tag
}

Example 3: unity find gameobject


ExampleObject = GameObject.Find("Hand");

Example 4: unity find object by name


using UnityEngine;
using System.Collections;// This returns the GameObject named Hand in one of the Scenes.public class ExampleClass : MonoBehaviour
{
public GameObject hand; void Example()
{
// This returns the GameObject named Hand.
hand = GameObject.Find("Hand"); // This returns the GameObject named Hand.
// Hand must not have a parent in the Hierarchy view.
hand = GameObject.Find("/Hand"); // This returns the GameObject named Hand,
// which is a child of Arm > Monster.
// Monster must not have a parent in the Hierarchy view.
hand = GameObject.Find("/Monster/Arm/Hand"); // This returns the GameObject named Hand,
// which is a child of Arm > Monster.
hand = GameObject.Find("Monster/Arm/Hand");
}
}

Example 5: unity gameobject.find


GameObject obj = GameObject.Find("/Parent/Child/ChildOfChild");

Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable