When you instantiate the SpawnObject, I assume you would want to add 1 to the SpawnCounter. Every time you spawn an object, you could reset the timer to start again from 5 seconds. If you want to spawn as many objects as SpawnCounterMax, you could only execute the timer update if SpawnCounter < SpawnCounterMax.
#pragma strict
var SpawnObject : GameObject;
var SpawnPoint : GameObject;
var SpawnCounter : int=0;
var SpawnCounterMax : int=1;
var spawnTime : float=5.0;
private var myTimer : float;
function Awake(){
myTimer = spawnTime;
}
function Update(){
if (SpawnCounter < SpawnCounterMax)
{
if (myTimer >1){
myTimer -= Time.deltaTime;
}
else if (myTimer <=1)
{
Instantiate(SpawnObject, SpawnPoint.transform.position, SpawnPoint.transform.rotation);
SpawnCounter++;
myTimer = spawnTime;
}
}
}
If you only want to spawn one object, set SpawnCounterMax to 1 and you’re good to go.