- Home /
Question about spawning enemies
Hi, I want to spawn my enemy prefab within a certain area which is a 10×10 square so the start point of the area is Vector2 (0, 0) and the end point is Vector2 (10, 10). I can spawn enemies on random positions but it won't look homogeneous obviously so what i want to do is spawning my enemy prefab within this certain area homogeneously. For instance a few spawn position could be; (1, 0) (2, 0) (3, 0) (1, 1) (2, 1) and so on. Can you point me a direction on how to do this type of spawn process? Thank you in advance
Answer by 1Time · Mar 06, 2015 at 02:20 PM
Can't you use a for loop to spawn all enemies and after every spawn add 1 to x pos and if x pos has reached x max than go to a new row. Something like this:
int currentX = 0;
int currentZ = 0;
int xMax = 3; //Desired x size of row
for(int i = 0; i < enemyAmount; i++)
{
spawnPos = Vector3(currentX,enemyHeight,currentZ);
//Instantiate enemy here with the spawnPos
currentX+=1;
if(currentX>xMax)
{
//Start with a new row
currentX = 0;
currentZ +=1;
}
}
Ha! Obviously it looks simple. I couldn't get my $$anonymous$$d and think about it. Thanks!
Your answer
Follow this Question
Related Questions
Event-based spawning 1 Answer
Instantiate Prefabs on "Grid" Pattern? 1 Answer
How would you make an in-game editor/object spawner? 1 Answer
List what spawner enemy spawned from? 1 Answer
why doesn't my custom function work ? 2 Answers