2
\$\begingroup\$

I'm just making a practice version of a basic 2D RPG, but I'm trying to build a spawner kind of object that could be scaleable across the entire game. That is, there would be multiple types of enemies, and each instance of such a spawner would have a specific set of enemies that it would spawn.

I'm sure the answer is very simple, but I'm at the beginning stages of all of this. I guess really I just want a simple list that I can attach to my object and add the enemy names to it so that it can draw from that to figure out what they would spawn.

\$\endgroup\$
2
\$\begingroup\$

I guess it is. Simply add a public array of type GameObject and drag and drop your enemy prefabs in it inside the inspector panel. Use Random.Range(x,y) to get a random int and use it this way:

r = Random.Range(0, enemyTypes.Length); //random.range normally gives back a float, therefore, you may need to use 1 instead of 0
Instantiate(enemyTypes[r], position, rotation);

Hope that was enough & I was able to help you :)

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.