Now I make public GameObject = number of type of object I need to define to create and pass variables to check the indexnumber of object I need to create
Ex. Script
if (Index = 1)
{
create object 1;
}
if (index = 2)
{
create object 2;
}
if I got 150 different object I need to create it 150 times, is anyway to make this shorter than the way like I do ?
using UnityEngine;
public class CreateObjects : MonoBehaviour
{
// The 150 different objects you want to create
public GameObject[] objectToBeSpawned;
// The index that define which object you want to create
public int index;
// The amount of how many objects you want to create
public int amount;
// Start is called before the first frame update
void Start()
{
// Assuming you only want to create the object(s) one time
for (int i = 0; i < amount; i++)
{
Instantiate(objectToBeSpawned[index]);
}
}
}