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 Kaltic · Jun 24, 2011 at 05:34 PM · spawnincreasefast

Enemy Spawning

The issue I am having and I is most likely because I am calling it in the Update function every second. It does follow my script in a way, but it spawns far quicker and far more than my script should. Also this is my entire spawning script in case you want to test it.

The reason I wrote my increase the spawn rate over time script like this was because I figured it would hold together and I don't know how to write an actually good increase over time spawning script.

 var side : int;
 var Enemy : GameObject;
 
 var timeToDecrease : float;                        // Time the spawner waits to spawn the next enemy
 var decreaseCounter : int;                        // After 4 enemies spawn, decrease time to wait
 
 var decreaseBool : boolean = true;            // Start/Stop first spawn rate decrease
 var decreaseBool2 : boolean = true;            // Start/Stop second spawn rate decrease
 
 function Start(){
     timeToDecrease = 3;
 }  
    
 function Spawn(){
 
     // Spawn the enemy, yeild for seconds, and increase counter
     Instantiate(Enemy,transform.position, transform.rotation);
     yield WaitForSeconds(timeToDecrease);
     decreaseCounter++;
     
     // When 4 enemies have spawned increase the spawn rate by .5 seconds
     if(decreaseCounter == 4 && decreaseBool == true){
         timeToDecrease -= .5;
         decreaseCounter = 0;
     }
     
     // If the enemy is spawning every .5 seconds the stop the spawn rate decrease
      if(timeToDecrease <= .5){
         decreaseBool = false;
      }
     
     // Once spawn rate is at .5 seconds decrease by .1 second until it reachs .1 second for each spawn
     if(decreaseCounter == 4 && decreaseBool == false && decreaseBool2 == true){
         timeToDecrease -= .1;
         decreaseCounter = 0;
     }
     
     //    If the enemy is spawning every .1 seconds then stop decreasing spawn rate
      if(timeToDecrease <= .1){
         decreaseBool2 = 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
0
Best Answer

Answer by Anxo · Jun 24, 2011 at 05:51 PM

I did not read all your code because it does not look like all of it has to do with your question, but if you are just trying to spawn things according to some kind of delay all game long you could call a function in start like this

 var delay : float = 10.0;
 
 function Start()
 {
 Spawn();
 }

then in that function you can use a "while true" to have a continues loop for the spawn of the game.

 function Spawn(){
 while(true)
 {
 Debug.Log("spawning enemy and waiting for "+delay);
 yield WaitForSeconds(delay);
 if(delay > 2)
 delay--;
 }
 
 
 }

hope that helps.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to match the speed of objects and the spawn speed of objects? 0 Answers

Increasing spawn rate over time 1 Answer

Increasing spawn rate over time 0 Answers

How increase and decrease and reset spawn rate over time? 1 Answer

Rounds increasing exteremely fast 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