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 kewlhead · Jan 05, 2012 at 09:39 AM · arrayenemyspawnwave

Spawn "n" Enemies Every "nth" Wave?

So I have my game spawning one kind of enemy every wave, and each wave, there are 5 more then last time, so Wave 1 has 5 enemies, Wave 2 has 10 enemies, etc. I'm not too familiar with arrays and I think that's how I would have to go about solving this, but have no idea where to begin...

I want to be able to make 5 of the simple enemies spawn every wave until the 5th wave, then on the 6th wave, it would reset so that only 5 of the simple enemies appeared, but then another kind of enemy spawned as well. It would look kind of like this:

 Wave:              Simple Enemies:             Dangerous Enemy:
 1                   5                          0
 .                  10                          0
 .                  15                          0
 .                  20                          0
 5                  25                          0
 6                   5                          1
 7                  10                          2

Thanks so much!

If you want to see the script I have so far, it's here: http://dl.dropbox.com/u/55162513/SpawnEnemiesEndless_Script.js

Comment
Add comment · Show 9
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
avatar image by0log1c · Jan 05, 2012 at 10:47 PM 0
Share

If you don't want to use an array and the logic stays the exact same, each wave could just spawn following the simple formulas: simple = (wave%5)*5; dangerous = (wave-5);

avatar image kewlhead · Jan 05, 2012 at 11:50 PM 0
Share

Sorry if I sound extremely, dumb, but what exactly does the wave%5 do? I haven't seen that before...

avatar image by0log1c · Jan 06, 2012 at 12:03 AM 0
Share

% is the modulus operator. It returns the remaining of a division. IE: 5%1=0, 5%2=1, 5%3=2, 5%4=1, 5%5=0.

avatar image kewlhead · Jan 06, 2012 at 12:16 AM 0
Share

So what would happen if the number got higher, say, 15? Wouldn't it spawn 50?

avatar image Apples_mmmmmmmm · Jan 06, 2012 at 03:01 AM 1
Share

Unless a for loop is nested within another, having the same variable declared shouldn't affect anything. They should act independently from each other.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by syclamoth · Jan 05, 2012 at 09:48 AM

Try having an array of symbolic 'wave' objects, each of which has information about what should be spawned that wave. Then, you can set them up in the inspector and have your waves spawn correctly!

 class SpawnWave
 {
     var weakEnemies : int;
     var strongEnemies : int;
 }

 var waves : SpawnWave[];

Then, when the time comes to spawn enemies for a given wave number, do this-

 var currentWave : SpawnWave = waves[currentWaveNumber];

 for (var i = 0; i < currentWave.weakEnemies; i++)
 {
     // Spawn a weak enemy!
 }
 for (var i = 0; i < currentWave.strongEnemies; i++)
 {
     // Spawn a strong enemy!
 }
Comment
Add comment · Show 4 · 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
avatar image kewlhead · Jan 05, 2012 at 02:45 PM 0
Share

So to make the "wave" objects, would I create a bunch of empties all with the same script, then in the inspector change the first one to say weakEnemies = 5 and strongEnemies = 0, and on another one it might say weakEnemies = 10 and strongEnemies = 5? If so, how could I get this code here to know which empty to call the information from?

Thanks for such a quick reply btw!

avatar image syclamoth · Jan 05, 2012 at 02:58 PM 0
Share

Who said anything about empties? You don't need more than one gameobject here. The array of waves will appear in the inspector! Try it, you'll see.

avatar image kewlhead · Jan 05, 2012 at 03:15 PM 0
Share

Okay, I took the "wave" objects literally as game objects... I had to add the currentWaveNumber as a variable that equaled zero, but when I go to change the inspector, the currentWave and the Wave arrays both ask for the number of weakEnemies and strongEnemies?

avatar image syclamoth · Jan 05, 2012 at 10:06 PM 0
Share

Sorry, currentWave shouldn't be a class variable. It should only exist within the scope of the function that spawns the wave. It gets declared immediately before the two for-loops.

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Way Point Assignment 4 Answers

Enemy Wave 1 Answer

Can anybody help me fix this wave spawning script please? 1 Answer

Can you name something that you spawned with a spawner script? 1 Answer

c# enemy's not spawning 1 Answer


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