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);
 }

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!

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 } } }