i made a spawner script where i put enemy spawners around the scene to spawn enemys at random intervals and positions
what ends up happening is that it spawns an enemy every frame from every spawn point and i dont know how to fix it (it doesnt show errors)
can someone help? this is the script in C#
Normally what I’d do is setup something like this:
float timeBtwSpawns = 5.0f; //let's test every five seconds
float currentTimeBtwSpawns;
//Now inside the Update method what you should be doing is
void Update ()
{
currentTimeBtwSpawns += Time.deltaTime;
if (currentTimeBtwSpawns > timeBtwSpawns)
{
//Do stuff to spawn in enemies here
//Reset currentTimeBtwSpawns
currentTimeBtwSpawns = 0.0f;
}
}
I think what is happening is that you need a constant value that you want to check something against (check that the current time is greater than the time to spawn) and since you are not resetting this value it might be constantly meeting the condition to spawn, what you can do to check this though is just do a simple debug log printout to see what the value is currently at:
(Debug.Log("TimeBtwSpawns: "+timeBtwSpawns)); //put this at the top of the update method and it should tell you where it's at