how to instantiate object in c# code example
Example 1: c# instantiate
// Instantiates 10 copies of Prefab each 2 units apart from each otherusing UnityEngine;
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 2: c# new object
//Declaring a new object of type Galaxy.
Galaxy aGalaxy = new Galaxy();