So In this game the player can find chests, these chests can have, at ramdom, one of ten different items.
So when the player opens a chest this happens:
// Mockup code
[SerializeField] GameObject[] items;
void OpenChest()
{
int index = Random.Range(0, items.Lenght);
Instantiate(items[index]);
}
The problem with this solution is that I need to drag the 10 items (gameobjects) to the chest’s script, and that’s for every chest in the game. It seems like a waste of resources. Is there a way to Instantiate or create an gameobject on the fly, without having an instance in the inspector. For example:
int index = Random.Range(0, items.Lenght);
switch(index)
{
case 0: Create(BlueCoin); break;
case 1: Create(Sword); break;
...
}