- Home /
Spawning objects?
Hello. I want to set up the enemy spawning system for my game and I have a three questions:
1:How can I make it so that every 4 seconds, 2 objects are randomly spawned within minimum/maximum/center xyz coordinates from 3 possible prefabs until the total number of objects equals 20?
2: How can I bypass the "spawn every 4 seconds" thing so that if the total number of objects spawned at the current time falls below a certain amount (so that the player doesnt get bored) a certain amount of enemies will spawn instantly, regardless of time?
3: I want to make the script multi-tiered, so the farther the player gets into the game, the tougher it gets. I want a value to increase with every enemy the player defeats (I know how to do that). As the value gets larger, I want the variables of the script to increase. So the script would be set up like this
:if value <20(){ Every 4 seconds, spawn 2 objects until the number of objects spawned at the current time =20 Possible object choices are "Enemy A", "Enemy B" "Enemy C"
:if value >20 and<40(){ Every 4 seconds, spawn 5 objects until the number of objects spawned at the current time =30 Possible object choices are "Enemy A", "Enemy B" "Enemy C" "Enemy D" Enemy E" "Enemy F"
Thanks.
Answer by Justin Warner · Dec 05, 2010 at 03:16 AM
1: Pauses: http://unity3d.com/support/documentation/ScriptReference/index.Coroutines_26_Yield.html
Creating the prefab: http://unity3d.com/support/documentation/ScriptReference/Object.Instantiate.html
Make spawn points, with random number, and different case each number with switch statement... http://answers.unity3d.com/questions/203/how-to-generate-a-random-number-inside-unity
Equals 20 use a if statement (if(amount <=20) {keepspawning()}
) and get the amount with tag (Theirs something in the docs you have to search...
- Keep on using that if statement on the update function, it'll work on its own.
As for 3.
I'd go about it with an array of enemy types, have it loop so that it's like
Array of enemies 1,2,3.
Spawn 1.
Wait 10 seconds.
Check if their's still 20.
Yes: Keep going No: Add until 20
Increment i.
If i=30 (30 seconds).
Spawn 2.
Check if 20...
etc.
This will spawn more than 20 though, which'll be good because difficulty goes up...
But yeah.
Good luck!
Your answer
Follow this Question
Related Questions
Instantiate object in random position inside a navmesh 1 Answer
Spawning different random objects at the same position? 2 Answers
Random array issue C# 2 Answers
Instantiate a random prefab at an objects location 3 Answers
Calling 2 specific random float numbers in random.range using array not working! 2 Answers