x


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.

more ▼

asked Nov 26 '10 at 10:10 PM

Tyler 2 gravatar image

Tyler 2
1.1k 211 246 264

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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...

  1. 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!

more ▼

answered Dec 05 '10 at 03:16 AM

Justin Warner gravatar image

Justin Warner
6.3k 19 27 65

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1683
x1095
x575

asked: Nov 26 '10 at 10:10 PM

Seen: 6862 times

Last Updated: Nov 26 '10 at 10:10 PM