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
1
Question by Ramunas · Jun 21, 2015 at 10:57 AM · infinitewavesspawning-enemies

How to make infinite enemies spawning wave system?

How to make a wave system, if I need to spawn different enemies (enemy1, enemy2, enemy3...) in multiple combinations, also sometimes with pauses. How should I make an algorithm for waves? By the way, I require infinite spawning system. It should look like:
wave 1: spawn 10 X enemy1
wave 2: spawn 20 X enemy1
wave 3: spawn 20 X enemy1, spawn 10 X enemy2
wave 4: spawn 20 X enemy1, Wait 5 seconds, spawn 20 X enemy2
wave 5: spawn 30 X enemy2
wave 6: spawn 30 X enemy1, Wait 5 seconds, spawn 10 X enemy3

With greater wave number - greater amount of enemies and they should be spawned in various combinations, but later in some waves enemies should be spawned of the same type, abilities.

Comment
Add comment · Show 2
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 oranmooney · Jul 03, 2017 at 03:04 PM 0
Share

i cannot wait to see an answer i have tried everything. good luck. up voted =]

avatar image Mercbaker · Jul 03, 2017 at 05:03 PM 0
Share

As long as the gameIsNotOver > run the spawnEnemy script.

At that point its just a logic problem of how you want to spawn the enemy. This would be specific to your game.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by TheDJBuntin · Jul 03, 2017 at 11:12 PM

I really didnt want to code the entire thing but ended up getting carried away. This is the jist of it:

 private int wave = 0;
 private int numOfTotalWaves = 10;
 private int numOfEnemyTypes = 3;
 private int[,] waveSpawnCount = new int[numOfTotalWaves, numOfEnemyTypes];
 private int aliveEnemies = 0; // Will count how many enemies are currently alive, MAKE SURE TO HAVE THIS DECREASE WHEN ONE DIES
 
 void Start()
 {
     //Set Wave 0 to 0 spawns because we dont want anything to spawn in wave 0.
     waveSpawnCount[0, 0] = 0;
     waveSpawnCount[0, 1] = 0;
     waveSpawnCount[0, 2] = 0;
     
     waveSpawnCount[1, 0] = 10;    //Store that we want 10 of Enemy 0 to spawn in Wave 1
     waveSpawnCount[1, 1] = 0;
     waveSpawnCount[1, 2] = 0;
     
     /*
     ...
     And So On
     ...
     */
 }
 
 void Update()
 {
     if(aliveEnemies <= 0)
     {
         if(wave <= numOfTotalWaves)
         {
             wave++;
             SpawnWave();
         }
     }
 }
 
 private void SpawnWave()
 {
     for(int enemyType = 0; enemyType != numOfEnemyTypes; enemyType++) // For every enemy Type
     {
       for(int i = 0; i < waveSpawnCount[wave, enemyType]; i++) // and for every number of units to spawn for that enemy type
       {
           SpawnEnemy(enemyType); // spawn that enemy type
           aliveEnemies++; // Add one to our alive enemies counter
       }
     }
 }
 
 private void SpawnEnemy()
 {
     switch(enemyType)
     {
         case 0:
         // Do whatever you do to load enemy 0
         break;
         case 1:
         // Do whatever you do to load enemy 1
         break;
         case 2:
         // Do whatever you do to load enemy 2
         break;
     }
 }

As for the wait 5 seconds and spawn more stuff thing. You have two options for expanding on the code that I've provided that I can think of. Either 1. Just include these things in the regular waves, this will get messy and isnt recommended but if you're just throwing something together quickly it'll probably be a easier/quicker solution. OR 2. Have a 2nd 2D Array (the thing where its int[,] that stores the values you have for "extra" waves - basically just duplicate everything there and rename the new ones to extraWaveSpawnCount or something like that and store the numbers you want in there and do the same thing as I do with spawning the regular wave except after a delay. You can save the delay in another array as well. ie private float[] extraWaveDelay = new float[numOfTotalWaves] then extraWaveDelay[0] = 0.0; extraWaveDelay[1] = 5.0f and have the current wave delay decrease by deltaTime by doing extraWaveDelay[wave] -= Time.deltaTime in Update and then if(extraWaveDelay[wave] <= 0) ... SpawnExtraWave(); etc.

Hope this helped.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Spawn waves & wait till it's killed, spawn again. 1 Answer

ai spawning please help 0 Answers

How to increase int every 5 waves? 1 Answer

How to prevent infinite loop when Array Index Is Out Of Range 2 Answers

How would I go about making infinite waves that get harder over time? 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