Timed instantiantion not quite working

I’ve been trying to create a wave effect for my game, so at certain times waves will spawn at specified places… (think side scrolling shooter)

I did have colliders working doing the same job, but they’re not ideal for this type of game, and inturn I tried to code a time script so that i can spawn prefabs at locations at certain times…

var wave2 :GameObject;
var wave3 :GameObject;

function Update () {
	if(Time.time == 5.0) {
    var wave2spawn = Instantiate(wave2, Vector3(-0.9712, 2, -11), Quaternion.identity);
	}
	if(Time.time == 10.0) {
    var wave3spawn = Instantiate(wave3, Vector3(1.237, 2, -9), Quaternion.identity);
}
}

Again, i’ve probably made fundamental errors, but its difficult to leanr without being taught! :wink:

The problem is that Time.time may not exactly be 5.0 or 10.0.

One solution could be to only spawn each object once - and set the wave-variable to null afterwards. And then test using ‘larger-than’ instead of 'equals. Like this:

var wave2 :GameObject;
var wave3 :GameObject;

function Update () {
    if(Time.time > 5.0 && wave2 != null) {
    	var wave2spawn = Instantiate(wave2, Vector3(-0.9712, 2, -11), Quaternion.identity);
    	wave2 = null;
    }
    if(Time.time > 10.0 && wave3 != null) {
    	var wave3spawn = Instantiate(wave3, Vector3(1.237, 2, -9), Quaternion.identity);
    	wave3 = null;
	}
}