Creating an aware mob spawner

Hello Everyone.

I’ve been trying to make a system that spawns AI, and stores them in a list at the same time, so when the 10 AI from the spawner die (or even just one) they will respawn.

So I managed to put them into a lit, but the prefabs don’t display due to them being in the list. So, how would I go abouts this?

Cheers.

Edit: I had an idea that I could in fact create the instances of the prefabs as a child object of the spawner. My only issue is that I don’t have a clue how to spawn a prefab as child.

GameObject go;
// your prefab instantiate
go = Instantiate(....
go.name = "enemy";

//parent to this object
go.transform.parent = transform;

tbh i’d keep the reference to each enemy as you instantiate it, so you can loop through them easy if you needed.

I do know how to instantiate game objects, it’s just that I don’t know how to keep track of them once made.

var thingToKeepTrackOf:GameObject;

thingToKeepTrackOf = Instantiate(…

Don’t know what you’re expecting exactly. Just make a variable and its yours forever until hell freezes over.

Alternatively add a script to the prefab which will control it once you “spawn” it with an instantiate.

cheers. I was just not sure if Inst- actually returned anything that can be used as reference.

I’ll give that a spin later today.

well it’s yours till hell freezes over or you destroy the instantiated object, and then it’ll become null :slight_smile:

unifycommunity.com/wiki/index.php?title=Enemy_Spawner

Here’s a pretty simple implementation of a spawner, perhaps you can adapt it to your needs?