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 arashsh · Mar 08, 2020 at 03:11 AM · timespawnresetincreasedecrease

How increase and decrease and reset spawn rate over time?

How I Can Increase And Decrease Spawn Rate Every Time I Want? i can Increase Not Decrease Or Reset

     public float nextDrop = 0f;
     public float dropInterval = 2f;
     public float changeInterval = 5f; 
     float delay = 3f;
     int minX = -6;
     int maxX = 6;
     int indexx;
     public Vector3 spawnvalue;
     public GameObject[] targets;
 
    private void Update()
   { 
      if(Time.time >= nextDrop)
      {
            Spawn();
            nextDrop += dropInterval;
            if(Time.timeSinceLevelLoad >= changeInterval) 
           {
             if(dropInterval > 0.3f)
             {
               dropInterval *= 0.92f;
             }
           
           }
            if(Time.timeSinceLevelLoad >= 50f)
           {
             if(dropInterval < 0.3f)
             {
               dropInterval = 2f; 
             }
           }
            if(Time.timeSinceLevelLoad >= 60f)
           {
             if(dropInterval > 0.3f)
             {
               dropInterval *= 0.92f;
             }
           }
           
  }
 }
 
  void Spawn()
  {
      GameObject spawn = Pool.Instance.GetPool();
      spawn.transform.position = new Vector3 (Random.Range (minX, maxX), spawnvalue.y, 
      targets[indexx].transform.position.z + 50 );
      spawn.SetActive(true);
  }





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 tormentoarmagedoom · Mar 08, 2020 at 11:50 AM

Hello!

Thanks for posting again, now is much easy to read your post!.

For your code, i see you spawn using Spawn() wich is called in the Update.

But i dont understand why you use Time.time to compare with nextDrop

Time.time is the time in seconds since the start of the game.

If you pretend to do something every X seconds, you have differnt options, but thisone you use is...mm strange and difficult to operate with.

The best solution is using IEnumeratorts (Corutines), really, they are very easy to use (also for beginers) and will give you control of timing functions. You can hold a function before continue or before commence again. I recommend you 100% to spend next 2 hours learning about corutines, there are several manuals andyoutube tutorials.

Another way can be creating a timer, similar of what you are doing in your script. But never using Time.time, instead you should have a float varaibe that increase with Time.deltaTime and when your variable reach some Maxvalue, you spawn again. And changing thes MAxValue will make change time between spawns.

There are so many posts about Repeat a function over time, about timers, about spawning.

You should take your time, reading Unity Answers and watching tutoprials. Speed is not a good friend when learning scripting.

Good luck!

Comment
Add comment · Show 4 · 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 arashsh · Mar 08, 2020 at 01:50 PM 0
Share

thanks for reply, i understand use coroutine i s so much better but i don't know how do every x seconds with coroutine and we have no tutorial about decrease spawn rate. you think i should do something like this?

 void update() { spawntime += Time.deltaTime; }
 
 IEnumerator Spawn() { while (true) { if(spawntime== 3f) { //startspawn } if(spawntime== 10f) { //increasespawn } if(spawntime== 30f) { //decreasespawn } } }

avatar image tormentoarmagedoom arashsh · Mar 08, 2020 at 02:07 PM 0
Share

Hello again.

We are developers, we talk about functions and variables.

" no tutorial about decrease spawn rate" means nothign while developing.

you want a tutorial to repeat a function every xome seconds, and change this seconds if needed, dont care if respawing, damaging, posionig... we are not the players.

You need to use corutine like this:

 float SecondToWait = 5f;
 
 void Start()
 {
 StartCorutine(Respawn())
 }
 
 IEnumerator Respawn()
 {
 //Respawn code
 yield return New WaitForSeconds(SecondToWait);
 StartCorutine(Respawn())
 }

If you change the SecondToWait value, the fucntion will wait different seconds time.

avatar image arashsh tormentoarmagedoom · Mar 08, 2020 at 02:31 PM 0
Share

thanks i use coroutine before and don't work for me but i try your method

Show more comments

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

127 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Increase/Decrease Over Time, Not Frames 1 Answer

How Increase And Decrease And Reset Spawn Rate Over 0 Answers

How To Add A Simple Speed Boost On Collision With A Specific Object With A Character Controller 0 Answers

slowly decrease value when in trigger 1 Answer

Problems with Spawner and timer. 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