- Home /
Adding a prefab to GameObject[] via script
Hey all,
I have a public GameObject[] enemies which I call with Random.Range to spawn waves of enemies for a top down shooter style game. I'd like to increase the pool of enemies by adding a new harder enemy each 10 waves or so.
Is there a way of doing what I'm describing via script in C# ? If not, what options do I have ?
TIP: When you have implemented object pooling with List's you can reuse your pool of objects by either adding a Script with a String or Enum value defining your Enemy Type, and ins$$anonymous$$d of destroying the Enemy on the kill you just call SetActive(false) on the object, and then when reusing you Reset Position and Rotation and call SetActive(true) and start moving your enemy, just as it were Instantiated the first time.
That way you can have many enemies and explosions without using the expensive Instantiate() every time you spawn a new Enemy or an Explosion, shot etc.