How to increase spawning speed?

Hello.

Im trying to increase speed rate of my spawning object. Now it’s spawning on 1.5f, and I want this speed to increase after some amount of time (lets say after every 10 sec it increases for 0.1f). Anyone know how to do that? Thanks for answers.

My code so far:

using UnityEngine;
using System.Collections;

public class Generate : MonoBehaviour {

public GameObject cubes;

void Start()
{
	InvokeRepeating("CreateObstacle", 3f, 1.5f);
}

void CreateObstacle()
{
	Instantiate(cubes);
}

}

Use a coroutine instead of invoke repeating.

Make a coroutine with a loop, inside the loop put a call to

yield return new WaitForSeconds(delayTime);

Adjust delay time as necessary.

public class CubeSpawner : MonoBehaviour {

    public GameObject cubes ;
    public float initialDelay ;
    public float finalDelay ;
    public float rampDuration ;

    protected float _delay ;
    protected float _runTime ;
    protected float _timeSinceSpawn ;

    public void Start() {
        _delay = initialDelay ;
        _runTime = _timeSinceSpawn = 0.0f ;
    }

    public void Update() {
        _runTime += Time.deltaTime ;
        _timeSinceSpawn += Time.deltaTime ;
        _delay = Mathf.Lerp( initialDelay, finalDelay, _timeSinceSpawn / rampDuration ) ;
        if ( _timeSinceSpawn > _delay ) Spawn() ;
    }

    protected void Spawn() {
        _timeSinceSpawn = 0.0f ;
        Instantiate( cubes ) ;
    }

}

using UnityEngine; using System.Collections;

public class Generate : MonoBehaviour {

    public GameObject cubes;
    float createRate = 1.5f, createRateTimer;
    float rateIncrease = 0.1f, initialCreateDelay =3.0f;
    int callCounter = 0, callsBeforeRateIncrease = 10;

    void Start(){
    createRateTimer = createRate + initialCreateDelay;
    }

    void Update(){
    createRateTimer -= Time.deltaTime;
    if(createRateTimer <= 0)
       {
       CustomInvoke();
       }
    }

    void CustomInvoke(){
    Instantiate(cubes);
    callCounter++;
    if(callCounter >= callsBeforeRateIncrease){
       createRate -= rateIncrease;
       callCounter = 0;
    }
   createRateTimer = createRate;
  }

}

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class Generate : MonoBehaviour 
{
	public float timer ;				//Time after which spawn time will decrease. In your case '10 s'.
	public float spawnTimer;			//Time after which Object spawns. In your case '1.5 s'
	public float decreasedSpawnTimer ; 	//Time which we will decrease to speed up Spawn. In your case '0.1 s'

	void Update()
	{
		timer -= Time.deltaTime;	//Decreases time
		spawnTimer -= Time.deltaTime;	//Decreases time

		if( spawnTimer < 0)	//Time when spawn happens
		{
			spawnTimer = decreasedSpawnTimer;	//Assigns the modified spawn time
			Debug.Log("Instantiate");	//Spawn command here
		}

		if( timer < 0)	//TIme when spawn time decreases
		{
			timer = 10;
			decreasedSpawnTimer -= 0.1f;	//Time by which spawn time is reduced.
		}

	}
}

You will need to add a case to stop decreasedSpawnTimer from going Negative. If need any more help. Don’t hesitate to ask.