my object instantiates to much

en#pragma strict

var rocket : boolean = false; 
var generate : boolean = false; 
var timer : float = 5;
var skyrocket : Transform; 
var min : float = 0;
var max : float = 5; 
var minz : float = 0;
var maxz : float = 5;  
var amount : float = 0; 
var remake : float = 15;

function Start () { 




}

function Update () { 

if(amount >= 1) 
generate = (false);

if(rocket){ 
timer -= 1 * Time.deltaTime;}  


remake -= 1 * Time.deltaTime; 



if(remake <= 0) 
generate = (true);
make(); 


hello i am trying to clone an object once every 15 seconds but a whole bunch keeps being cloned i remove it out of d update function but it still do not work right.

Not actually implemented a co-routine in UnityScript but here goes.

var trigger : bool = true;

function MakeObject()
{
      trigger = false; //Set trigger to false so MakeObject won't get called again
      GameObject.Instantiate(skyRocket);
      yield WaitForSeconds(900); //Wait for 900 secs (15 mins)
      trigger = true; //After the wait set trigger to true so the function will get 
                      //called on the next update function call.
}

function Update()
{
    //Your code..
    if(trigger == true)
       {
             MakeObject();
       }
}

That is totally off the top of my head, so might work, might not :wink: Give it a try. You don’t need the timer logic using this way.

So yeah we start off on the first update with trigger being true, so on the first call of update MakeObject will get called.

When we enter MakeObject it first sets trigger to false, so that the coroutine won’t get called on the next update call (and any other update call within the next 15 minutes).

We then instantiate a new GameObject (clone the object), and call yield WaitForSeconds, simply put that means that the line under it where we set trigger to true, doesn’t get executed for the 900 second wait.

After the 900 second wait trigger gets set to true. So in the next update function call trigger is true, so we call MakeObject again… thus another GameObject is instantiated after 15 minutes.