Hello. I have a game right now where my character is steering through cubes. Right now my cubes spawn 100 units in front of the player, each 0.75 seconds. I want it to spawn cubes faster and faster all the way down to 0.25, and then that should be the fastest. Here is some of the code i have now:
void Update () {
if ( spawnTime < Time.time ) {
CreateCube ( spawnDistance + character.position.z );
spawnTime += delayBetweenSpawns;
}
}
}
A cheap way to do it would be to increase your delayBetweenSpawns value every time you wished to reduce the time between spawns. Alternatively, you’d reduce the value you’re comparing spawnTime to.
This code adapts your current block and makes it dependant on Time.deltaTime instead. When you tap the Increase Difficulty box on the Inspector at runtime (or set it to true using code, whichever way you want), it will knock the timeBetweenCubes down a tenth of a second.
public float timeBetweenCubes = 0.75f;
public float spawnTime = 0;
public bool increaseDifficulty = false;
//
void Update (){
//
spawnTime += Time.deltaTime;
if ( spawnTime > timeBetweenCubes ) {
CreateCube ( spawnDistance + character.position.z );
spawnTime += delayBetweenSpawns;
spawnTime = 0;
}
if(increaseDifficulty){
increaseDifficulty = false;
timeBetweenCubes -= 0.1f;
if(timeBetweenCubes < 0.25f) timeBetweenCubes = 0.25f
}
//
}
All you have to do is reducing the spawn delay:
void Update () {
if ( spawnTime < Time.time ) {
CreateCube ( spawnDistance + character.position.z );
spawnTime += delayBetweenSpawns;
if(delayBetweenSpawns > 0.25f)
delayBetweenSpanse -= 0.05f; //or whatever value you want.
}
}