Hello there. I am programming a 2D shooter game where lots of zombies will try to kill the player. I manage this situation like follows (very important to note: this game is supposed to be released on Android, that is, limited memory and CPU resources are available).
1.) In the scene editor, I create one zombie GameObject. This will be the initial (mould) zombie.
2.) After the game starts, time starts to count down until a new zombie is created. This time, “thresholdTime”, will be the time between new initializations of zombies. If I set thresholdTime=5, that would mean that after 30 seconds I would have dynamically instantiated 6 new zombies GameObjects. I store them in a List.
3.) Whenever the player kills a zombie, that zombie GameObject is destroyed.
I know this creating-destroying cycle is not the best way to approach my problem.
I have heard about Object Pooling but I don’t know how to implement this concept.
Finally I would like to tell you one possible workaround I thought about: just initialize a fixed number of zombies (say, 30 of them) and locate them at arbitrary (random) distances from the player. Whenever the player kills a zombie, I would not destroy that instance but rather “transport” that GameObject to a new, random position (out from screen, giving the sensation that this zombie has been killed). I don’t know if this is a good way: what if I need to increase the difficulty and instantiate new zombies?
What do you think?
Thanks