Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Aspect13 · Dec 15, 2018 at 05:48 PM · spawnspawningwavesspawning-enemieswave

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

Hey, I want to make wave spawning script. I don't want to just spawn waves in the loop because after some time there will be 9999 enemies. I want to spawn a wave of monsters and wait till player kills them then spawn next wave. I was thinking about making a list of enemies, add enemies to it and when it's empty then spawn another wave. The problem is I have 3 enemies and player would have to kill all three of them at once to spawn another wave? I wanted to start the coroutine in an update function. Also I wanted to ask if I can add GAMEOBJECTS to the list if they ARE NOT on the scene? The code would look like this:

 public GameObject Enemy1;
 public GameObject Enemy2;
 public GameObject Enemy3;
 
 public Vector3 spawner1Pos = new Vector3(-36.5f, 3.67f, 88.2f);
 public List<GameObject> enemies = new List<GameObject>();
 
 private void Start()
 {
       enemies.Add(Enemy1);
       enemies.Add(Enemy2);
       enemies.Add(Enemy3);
 }
 
 private void Update()
 {
       if(enemies.Count == 0)
       {
               for(int i = 0; i < 3; i++)
               {
               Instantiate(Enemy1, spawner1Pos, Quaternion.identity);
               }
       }
 }

It's just an example code but it would look like this.

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 Vega4Life · Dec 15, 2018 at 07:08 PM

Here is an idea with a singleton spawn manager. Just use it for some reference, but basically, when an enemy dies, you send a notification into the manager. The manager will determine when to spawn more. It also spawns the first wave of enemies too. Should give you some ideas.


 // Place in your scene somewhere
     public class SpawnManager : MonoBehaviour
     {
         // Singleton
         static SpawnManager instance;
         public SpawnManager Instance
         {
             get
             {
                 if (instance == null)
                 {
                     instance = FindObjectOfType<SpawnManager>();
                 }
 
                 return instance;
             }
         }
 
         [SerializeField] GameObject enemyPrefab;    // Link the enemy prefab to make clones of -- this could be a list of prefabs that you randomly choose from
         [SerializeField] int spawnCount = 5;        // as many as you want
 
         int currentEnemyCount;
 
         // Our property will take care of spawning as it decrements
         public int CurrentEnemyCount
         {
             get { return currentEnemyCount; }
             set
             {
                 currentEnemyCount = value;
                 if (currentEnemyCount <= 0)
                 {
                     CreateEnemies();
                 }
             }
         }
 
 
         void Awake()
         {
             CreateEnemies();
         }
 
         void CreateEnemies()
         {
             for (int i = 0; i < spawnCount; i++)
             {
                 Instantiate(enemyPrefab);   // Add in spawn locations - whatever you want
                 currentEnemyCount++;
             }
         }
 
         /// <summary>
         /// CALL THIS FROM ENEMY SCRIPT WHEN IT DIES
         /// The call would look like SpawnManager.Instance.OnEnemyDeath();
         /// </summary>
         public void OnEnemyDeath()
         {
             // As this gets to zero, it will spawn more through the property
             CurrentEnemyCount--;
         }



Comment
Add comment · Show 1 · 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 Aspect13 · Dec 15, 2018 at 08:47 PM 0
Share

Hey Thanks for your answer but I made some code myself also before your answer and I want you to take a look, if you can of course, and see if you can help me with the problem I have with this code... I have to add, I wanted to make more "advanced" wave system with enemies increasing each wave etc. I exceeded 3000 characters here so I can't add the answer so I will just link the screenshots, they're from imgbb. There are 10 parts of them :/

https://ibb.co/album/dEvkDv/?sort=date_desc&page=1

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

100 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

Related Questions

How to increase int every 5 waves? 1 Answer

How to make the clones of a zombie continue to clone? 2 Answers

How to increase the spawn rate of an object over time? 2 Answers

How to spawn enemies at different locations and avoid overlapping each other 2 Answers

ai spawning please help 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