Hi. In my game I have a player climbing up a wall and objects fall on the player. (Credits to @static_cast). I was wondering how I can increase the spawn rate of the object every 30 seconds. In other word to make more objects fall as the game goes on. How should I do this?
Hi again, take a look at this code. I have not ran this so maybe there is a typo somewhere :
private var fSpawn_Speed : float;
function Start() {
//Set initial Spawn Speed
fSpawn_Speed = 10f;
//Start Spawning.
InvokeRepeating("subSpawn_Object", 0, fSpawn_Speed);
//Start the Spawn speed adjust in 30 seconds.
InvokeRepeating("subIncrease_Spawn_Speed", 30, 30);
}
function subIncrease_Spawn_Speed() {
var fSpeed_Increase : float = 1f;
//Cancel the current subSpawn_Object Invoke.
CancelInvoke("subSpawn_Object");
//This will limit the spawn speed to a min of 1.
if ((fSpawn_Speed - fSpeed_Increase) < 1) {
fSpawn_Speed = 1f;
} else {
fSpawn_Speed = fSpawn_Speed - fSpeed_Increase;
}
//Restart subSpawn_Object with new repeat time.
//You may want to adjust for the time since the last spawn
//by setting up a time since last spawn var and using that
//calculation rather than 0.
InvokeRepeating("subSpawn_Object", 0, fSpawn_Speed);
}
function subSpawn_Object() {
//Your Spawn code.
}
Here’s what you could do:
private float nextDrop = 0f; //The time for the next item to spawn
private float dropInterval = 10f; //The interval between spawned items
private float changeInterval = 30f; //The interval between changing the interval between spanwed times. :P
void Update()
{
if(Time.time >= nextDrop) //If ready to spawn
{
SpawnObject();
nextDrop += dropInterval; //Set next spawn time
if(Time.time >= changeInterval) //If ready to change spawn interval
{
if(dropInterval > 1f) //Change spawn interval to 3/4ths what it was
dropInterval *= 0.75f;
else //Make sure dropInterval stays above 1.
dropInterval = 1f;
}
}
}
Download this free asset in which there are 4 games.
One of the games uses Spawn function which is what you need.
C# game examples by M2H
Unity Asset Store - The Best Assets for Game Making Play the Egg bucket Game ( thats what you need )