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 dinneenio · Mar 12, 2014 at 09:38 AM · spawnrespawnzombiewaves

WaveSpawn Script. Help

Can someone help me with this i think there is something wrong with the script. It is supposed to spawn 5 enemies in round 1, 10 in round 2, 15 in round 3 etc But when all the enemies in any round are dead (enemyCounter == 0) the script doesn't start spawning again.

 please help.
 
     var spawnPoints : Transform[];
     var zombiePrefab : GameObject[];
     
     var yeildTimeMin = 2;
     var yeildTimeMax = 5;
     
     static var enemyCounter = 0;
     
     var spawnXOffsetMin = 0;
     var spawnXOffsetMax = 0;
     
     var spawnZOffsetMin = 0;
     var spawnZOffsetMax = 0;
     
     var defaultSpawnNum = 5;
     
     var isSpawning = false;
     
     var waveNum = 1;
     
     
     function SpawnEnemies(wave : int)
     {
         var spawnNum = (defaultSpawnNum +  5 * (wave - 1));
         
         isSpawning = true;
         
         for(var i = 0; i < spawnNum; i++)
         {
             yield WaitForSeconds(Random.Range(yeildTimeMin, yeildTimeMax));
             
             var object : GameObject = zombiePrefab[Random.Range(0, zombiePrefab.Length)];
             var positions : Transform = spawnPoints[Random.Range(0, spawnPoints.Length)];
             
             Instantiate(object, positions.position + Vector3(Random.Range(spawnXOffsetMin, spawnXOffsetMax), 0, Random.Range(spawnZOffsetMin, spawnZOffsetMax)), positions.rotation);
             
             enemyCounter ++;
         }
         
          isSpawning = false;
     }
     
     function UpdateWave()
     {
         waveNum += 1;
         gameObject.GetComponent(AI_Damage).maxHealth += 50;
         SpawnEnemies(waveNum);
     }
     
     function Start () 
     {
         SpawnEnemies(waveNum);
     }
     
     function Update () 
     {
         if(enemyCounter == 0 && !isSpawning)
         {
             UpdateWave();
         }
     }
Comment
Add comment · Show 4
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 OSG · Mar 12, 2014 at 09:46 AM 0
Share

Did you try to print enemyCounter variable in update before if() statement? I don't see code which decreases enemyCounter, too.

avatar image dinneenio · Mar 12, 2014 at 11:48 AM 0
Share

oh ok. how do you think i should go about doing that? es i did and your right its not counting down. how do you think i should implement that? i was thinking about adding the enemy health and when that reaches 0 destroy the game object and then $$anonymous$$us the counter by 1?

avatar image JonTakahiro · Mar 12, 2014 at 12:32 PM 0
Share

That should work yes. Track the enemy health, then destroy the object once it's health is gone and reduce the enemyCounter by 1 as you said. Currently you don't have any code I can see actually decreasing that counter so it'll never hit the update function.

avatar image dinneenio · Mar 12, 2014 at 02:07 PM 0
Share

ok i've broken it all together! it doesn't seem to be working for me at all! any chance someone could just change the code so i can see where i'm going wrong...?

0 Replies

· Add your reply
  • Sort: 

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

21 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

Related Questions

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

How would I create a script that spawns objects more frequently as time goes on? 3 Answers

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

Character respawns invisable? 1 Answer

Spawning a new player instance (UNET) 3 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