unity instantiatwe code example
Example 1: unity create gameobject from prefab in script
using UnityEngine;
public class example : MonoBehaviour
{
public GameObject prefab;
void Start()
{
Instantiate(prefab, new Vector3(0, 0, 0), Quaternion.identity);
}
}
Example 2: unity instantiate
clone = Instantiate(original);
clone = Instantiate(original, new Vector3(0, 0, 0), Quaternion.identity, cloneParent.transform);
Example 3: c# instantiate
using System.Collections;public class ExampleClass : MonoBehaviour
{
public Transform prefab;
void Start()
{
for (int i = 0; i < 10; i++)
{
Instantiate(prefab, new Vector3(i * 2.0F, 0, 0), Quaternion.identity);
}
}
}
Example 4: unity instantiate prefab
Instantiate(cube, Vector3 (x, y, 0), Quaternion.identity);