Unity create gameobject code example
Example 1: unity create gameobject
SpawnedObject = new GameObject("Created GameObject");
Example 2: unity create gameobject with component
GameObject go = new GameObject("Test", typeof(MeshRenderer), typeof(MeshFilter), typeof(YourScript));
Example 3: how to add a gameobject
public void AddGameObject()
{
GameObject testObject = new GameObject("Name_1");
}
Example 4: create gameobject unity
using UnityEngine;
public class InstantiationExample : MonoBehaviour
{
public GameObject myPrefab;
void Start()
{
Instantiate(myPrefab, new Vector3(0, 0, 0), Quaternion.identity);
}
}
Example 5: unity create empty gameobject in code
objToSpawn = new GameObject("Cool GameObject made from Code");