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 /
This question was closed May 23, 2021 at 01:10 PM by Bunnytoes for the following reason:

Fixedish

avatar image
0
Question by Bunnytoes · May 22, 2021 at 12:51 PM · spawning problems

New spawn help

I have system for the way the enemies spawn, but it doesn't spawn correctly, here is the code

using System.Collections;

using UnityEngine;

using UnityEngine.UI;

public class WaveSpawner : MonoBehaviour

{

public static int EnemiesAlive;

 public Wave[] waves;
 public Transform SpawnPoint;



 public float TimeBetweenWaves = 7f;
 private float countdown = 3f;

 public Text waveCountdownText;

 public GameManager gameMaster;


 private int WaveIndex = 0;


 void Start ()
 {
     EnemiesAlive = 0;
 }


 void Update()
 {
     if (EnemiesAlive > 0)
     {
         return;
     }

     
     if (WaveIndex == waves.Length)
     {
         gameMaster.WinLevel();
         this.enabled = false;
     }


     if (countdown <= 0f)
     {
         StartCoroutine(SpawnWave());

         countdown = TimeBetweenWaves;
         return;
     }

     countdown -= Time.deltaTime;

     countdown = Mathf.Clamp(countdown, 0f, Mathf.Infinity);

     waveCountdownText.text = string.Format("{0:00.00}", countdown);






 }

 IEnumerator SpawnWave()
 {
     
     PlayerStats.Rounds++;

     Wave wave = waves[WaveIndex];

     EnemiesAlive = wave.count;

     for (int i = 0; i < wave.count; i++)
     {
         SpawnEnemy(wave.enemy);
     
         yield return new WaitForSeconds(1f / wave.rate);
     }
     WaveIndex++;

 }

 void SpawnEnemy(GameObject enemy)
 {

     Instantiate(enemy, SpawnPoint.position, SpawnPoint.rotation);
     




 }

 


}

I want them to spawn when the previous wave dies alt text

alt text

they all spawn like this yellow, 2 blue 1 green 3 blue together in one wave, instead it should be one blue until it dies, 2 blue until that wave dies, 3 blue until that wave dies, 3 green until that have dies and after 10 yellow are spawned and killed the level should end

screenshot-2021-05-21-151529.png (57.1 kB)
screenshot-2021-05-21-151608.png (82.3 kB)
Comment
Add comment · Show 11
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 logicandchaos · May 22, 2021 at 01:39 PM 0
Share

I can't read that can you post your code properly formatted?

avatar image logicandchaos · May 22, 2021 at 01:41 PM 0
Share

I would have a variable waveSize or numberOfEnenies and then every time you kill an enemy the value decreases then when it is 0 you start the next wave.

avatar image Bunnytoes logicandchaos · May 22, 2021 at 04:07 PM 0
Share

I have a way to do that for the enemies alive to go down

avatar image gawynross · May 22, 2021 at 04:46 PM 0
Share

But what happens? Does it not spawn in or does it spawn in too quickly or something else?

avatar image Bunnytoes gawynross · May 22, 2021 at 04:55 PM 0
Share

they all spawn like this yellow, 2 blue 1 green 3 blue together in one wave, instead it should be one blue until it dies, 2 blue until that wave dies, 3 blue until that wave dies, 3 green until that have dies and after 10 yellow are spawned and killed the level should end

avatar image gawynross Bunnytoes · May 22, 2021 at 05:03 PM 0
Share

One last question, is there any reason why wave 0, 1, and 2 have different prefabs?

Show more comments
avatar image Bunnytoes · May 22, 2021 at 09:19 PM 0
Share

@gawynross where should I put that? also the EnemiesAlive = WaveIndex doesn't work

avatar image gawynross Bunnytoes · May 24, 2021 at 06:52 PM 0
Share

You would do EnemiesAlive = waves[WaveIndex].enemyCount (enemyCount or something). But, you closed the question so I guess you fixed it. Although, I am curious so…, what was the solution?

avatar image Bunnytoes gawynross · May 27, 2021 at 02:50 PM 0
Share

I added a ton of waves and since they all spawned at once it made it playable, I would have liked it to work the normal way but I did what I had to

Show more comments

1 Reply

  • Sort: 
avatar image
0

Answer by gawynross · May 22, 2021 at 05:19 PM

The only thing I can think of is that your EnemiesAlive count is going up as you spawn in the enemies. It should be set as the total amount of enemies right away. I’ll keep looking for other solutions if this doesn’t work.

Comment
Add comment · Show 3 · 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 Bunnytoes · May 22, 2021 at 06:11 PM 0
Share

@gawynross I tried adding EnemiesAlive = waveIndex and that didn't work, people on replit said it was because the EnemiesAlive was static

avatar image gawynross Bunnytoes · May 22, 2021 at 07:49 PM 0
Share

Ah, so did that solution work?

If it didn’t I think you would want to do EnemiesAlive = waves[WaveIndex].Count; I don’t know your variable name for the total enemies in a wave, so I will just assume it is Count.

avatar image Bunnytoes gawynross · May 22, 2021 at 09:26 PM 0
Share

I could also bump of some setting like crazy and make it so if enemies alive = 0 then you win level, lives would go down to 5

Follow this Question

Answers Answers and Comments

119 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

Related Questions

Objects spawning in each other 1 Answer

im having problems spawning these prefabs in a grid next to each other with some spacing thanks in advance 0 Answers

Object Pooling Spawn,Unity slows down when object pooling,Unity Slows down when Object Pooling 1 Answer

How to spawn all humans at once and activate then with time? 1 Answer

Why doesn't my spawning code work? 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