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
1
Question by Xatoku · Aug 14, 2011 at 08:59 PM · arrayenemyspawnsequence

Enemy Wave

Hey all, I'm new to Arrays and I've got my script spawning 1 enemy every wave but I wanted to make it so that the script will spawn +1 enemy every new wave (Wave 1 = 1, Wave 2 = 2, etc.) but I'm not sure how. Would someone mind making my script do that and explaining what they did so I can use it again in the future?

 var textColor = Color.yellow;
 var NumberEnemies : int;
 var WaveNumber = 0;
 var NewWave : boolean = false;
 
 var SpawnPoints : Transform[];
 var Enemies : Transform[];
 
 function Awake () {
    guiText.material.color = textColor;
 }
 
 function Update(){
     NumberEnemies = ((GameObject.FindGameObjectsWithTag("Enemy").Length) - 1);
     
     guiText.text = "Wave: " +WaveNumber;
     
     if(NumberEnemies == 0 && !NewWave){
         NewWave = true;
         WaveNumber += 1;
         SpawnEnemies();
     }
 }
 
 function SpawnEnemies(){
     SpawnEnemy = Instantiate(Enemies[0],SpawnPoints[0].position,SpawnPoints[0].rotation);
     NewWave = false;
 }
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
1

Answer by Dreamish · Aug 21, 2011 at 04:42 AM

Just add a for loop around the spawning code:

Instead of just

 SpawnEnemy = Instantiate(Enemies[0],SpawnPoints[0].position,SpawnPoints[0].rotation);

You can write

 for (var i = 0; i < WaveNumber; i++) {
     SpawnEnemy = Instantiate(Enemies[0],SpawnPoints[0].position,SpawnPoints[0].rotation);
 }

This will loop that piece of code as many times as the wave you're on. Since you've also put your spawn locations and enemies in arrays, you can change the indexes to for example Enemies[i], using the iterator for the loop (the counting variable) to spawn the enemy in location 0 of your array in the first wave, the enemies at locations 0 and 1 at the second, locations 0, 1 and 2 for the thrird wave and so forth, since the foor loop starts counting the i at 0 and continues up as long as it's smaller than WaveNumber. For this you need to make sure to have as many added enemies in your array as waves though. =)

Good luck!

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 eliteslayer · Dec 23, 2013 at 02:53 AM 0
Share

Is there a way to increase the number of enemies after each wave because i could really use that. just curious.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Can anybody help me fix this wave spawning script please? 1 Answer

Spawn "n" Enemies Every "nth" Wave? 1 Answer

Way Point Assignment 4 Answers

Play Audio in sequence from children objects 3 Answers

Array problem,different result 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