Time for action – Just five more minutes mom
Let's say instead of spawning enemies straight away when the game started, we wanted them to spawn after say, 10 seconds. That should give us enough time to start running.
Let's create a new function in
AwesomeEnemySpawner
calledTimedEnemySpawn
. We'll create the timer here:function TimedEnemySpawn() { SetTimer(10, false, 'SpawnEnemy'); }
The parameters for the
SetTimer
function are pretty easy. The first one is the amount of time for the timer. The second is an optionalbool
that controls whether or not we want the timer to run in a loop, in this case it would run every 10 seconds if we set it to true. The third parameter is the name of the function we want the timer to call when the time runs out. In this case, it will call the function that actually spawns the enemy.With this new functionality, we're going to need to keep a closer eye on the enemies we're spawning. If the spawner has already spawned an enemy, we don't want it to spawn another...