Adding a timer to spawner

So for class im making a project that uses one button only and not allowed the default rigidbody physics. I made all the movement and distance restrictions for the character my self but i need fish to spawn and cant seem to make it work. This is a script i found on the site and it just makes them all spawn everywhere, within the range limitation. How can i add a timer to this so they spawn periodically.

var thePrefab : GameObject;
var range: float = 12; // set the +/- range around the empty object

function Update () {
var pos = transform.position; // get this object’s position
pos.y += Random.Range(-range, range); // add a random x offset around it
var instance : GameObject = Instantiate(thePrefab, pos, transform.rotation);
}

var thePrefab : GameObject; var range: float = 12;
function Start(){
InvokeRepeating(“Spawn”,0.01f,5.0f);
}
function Spawn () {
var pos = transform.position;
pos.y += Random.Range(-range, range);
var instance : GameObject = Instantiate(thePrefab, pos, transform.rotation);
}

With InvokeRepeating() the first parameter is the function you want to use, the second is when do you want the first call, I put 0.01f because 0.0f is buggy and call the function twice. Then the third parameter is the frequency of call. Every 5 seconds.

Invoke repeating… of course :slight_smile: thanks so much works like a charm