gameobject unity code example
Example 1: unity find gameobject
ExampleObject = GameObject.Find("Hand");
Example 2: gameobject in unity c#
public GameObject myObject;
void Start()
{
myObject.name = "myObjectsNewName";
}
Example 3: unity create gameobject
SpawnedObject = new GameObject("Created GameObject");
Example 4: c# unity gameObject.script
void Update()
{
string Thing = gameObject.GetComponent<CustomScriptName>().Variable;
if (Thing == "String1")
{
DoStuff();
}
if (Thing == "String2")
{
DoOtherStuff();
}
}
Example 5: create gameobject unity
using UnityEngine;
public class InstantiationExample : MonoBehaviour
{
public GameObject myPrefab;
void Start()
{
Instantiate(myPrefab, new Vector3(0, 0, 0), Quaternion.identity);
}
}