I've got a linear-style game where you scroll through a level all the way to the end automatically without having to hand-place them.
My idea for spawning enemies works a little bit like this:
- Each level has some sort of "LevelSpawn" script.
- In it, I can set the number of enemies that will spawn by using the inspector to set the number of elements in a GameObject array.
- I'll fill in all the objects with the prefab enemies I wish to spawn, in order of appearance.
- I'll then use another array of floats. These floats would determine WHEN each enemy in the list will spawn. So if Time[0] is 1.0F, then SpawnedEnemy[0] will be created.
- Finally, I need a value to say where, horizontally, each enemy will spawn (they'll move downward by themselves from their own AI).
I'm having trouble thinking of how to string all this together and make it work.
Should I be going for a bunch of 1-dimensional arrays and finding ways for them to talk to each other, or should I be utilizing a 2-dimensional array somehow?
What I have right now is:
public GameObject[] EnemiesToSpawn;
public float[] TimeToSpawnEnemies;
But I'm not sure how I'm going to actually get this running smoothly. I thought I would have a timer variable, and constantly check to see if it's time to spawn a new enemy, but I don't know how I would turn it off and avoid repeatedly spawning an enemy after his time has come to appear (thus probably freezing the game...).
Should I think of another way of doing this entirely? If so, what do you suggest?