Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Tyler 2 · Nov 26, 2010 at 10:10 PM · instantiateobjectrandom

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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

  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!

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

No one has followed this question yet.

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges