How to instantiate a randomly picked ScriptableObject?

81 Views Asked by At

Im new to Unity and c#, I've been making a turn based game following one of Brackeys tutorial and i've added scriptable objects to it. Im looking to instantiate a random enemy everytime a fight starts.

Here's the lines that should be useful : ImageOfMyCode enter image description here The resources.LoadAll("Enemies") seems to work since I made 3 scriptable objects and the debug log also says 3.

Im really struggling past this to then shuffle allEnemies and instantite the randomly picked one.

Any help and guidance will be appreciated.

1

There are 1 best solutions below

0
On

The error you get for the Instantiate is because you pass a number instead the object that you want to instantiate, you can read more about it here: Object.Instantiate

What you can do is the following:

var randomRange = Random.Range(0,allEnemies.Length);
GameObject enemyGO = Instatiate(allEnemies[randomRange],playerBattleStation) as GameObject;