Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
  • Help Room /
avatar image
0
Question by jab0217 · Mar 17 at 10:14 PM · spawningdelaywavesspawning-enemies

New wave always spawns with wrong amount of enemies / also does not delay

Essentially I am trying to make a game in which one enemy of type slow spawns for every round completed so far (# of slow enemies = wave #), and one enemy of type fast spawns for every even round thats been completed (#_of_fast_enemies++ every other wave). However, the game always spawns one slow enemy for the first two consecutive rounds, and then one slow and one fast enemy for every round after that.

     void Update()
     {
         enemyCount = GameObject.FindGameObjectsWithTag("Enemy").Length;
         if ((enemyCount == 0) && waveDone)
         { 
             spawnWave(waveCounter);
 
         }
 
 
         if (Input.GetKeyDown(KeyCode.LeftArrow))
         {
             SpawnLeftCannonBalls();
         }
         if (Input.GetKeyDown(KeyCode.RightArrow))
         {
             SpawnRightCannonBalls();
         }
     }
 
 
 
     private void spawnWave(int waveCount)
     {
         waveDone = false;
         StartCoroutine(WaveCooldown());
  
 
         int i = 0;
         int j = numOfFastEnemies;
         while (i < waveCounter)
         {
             Instantiate(slowEnemy, new Vector3(-6, 3.5f, 0), gameObject.transform.rotation);
 
             if (j > 0)
             {
                 Instantiate(fastEnemy, new Vector3(-6, 3.5f, 0), gameObject.transform.rotation);
                 j--;
             }
             i++;
 
             StartCoroutine(SpawnCooldown());
         }
 
         if (waveCounter % 2 == 0)
         {
             numOfFastEnemies++;
         }
 
         waveCounter++;
         waveDone = true;
     }

I am also trying to make it such that the waves begin spawning enemies after a delay, and that the time between enemies spawning during the wave is delayed so that the enemies will be staggered. I tried to implement this with Coroutines and IEnumerators and this is just simply not working (no delay for either case at run time).

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

Answer by Cjmaster · Mar 18 at 08:46 AM

Im not quite sure because some part of the Code is missing.

But to make it clear. The Coroutine will be waited for X Amount you defined as Return value. But only the corutine. All the other code Part which are before, after and the regular update will continue.

You can image it like a Parking. He will start the Coroutine do the stuff inside and then place it somewhere for X Secound.

If you want your code to be blocked, you can await with the await key word for the TIme. But that is a poor design choice.

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

179 People are following this question.

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

Related Questions

Help with timed wave defense game 0 Answers

How do I make the enemies continue spawning? 1 Answer

problem when i spawn to many Enemy the game be slower 1 Answer

TD spawn more than one enemy 1 Answer

Improving script which Spawns enemies up to a required number 0 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