Help with WaitForSeconds

Hello, I need your help!!, I´m having trouble with te following script:

//Inspector Variables

var shapeColor : Color[ ];
var respawnWaitTime :float=2.0f;
var posx:float;
var posy:float;
var Shpere:GameObject;

function Start()
{
//Set a GameObject on an initial position and give a color
var position=Vector3 (posx,posy,0);
transform.position=position;
RandomColor();
}

function MakeBox(){

//Store an initial position
var position=Vector3 (posx,posy,0);
//Wait some seconds before create a new box
RespawnWaitTime();
//Create a new Box with an initial position
Instantiate(Box,position,transform.rotation);

}

function OnTriggerEnter (myTrigger : Collider) {

//If a collision with specific object occurs
if(myTrigger.gameObject.name == “me”){
//Destroy this gameObject
Destroy(gameObject);
//Call MakeBox
MakeBox();
}
}

function RespawnWaitTime()
{
//Call function to change the color
RandomColor();
//Wait for 3 seconds
yield WaitForSeconds(3);

}

function RandomColor()

{
//Check if there are an arrey with colors
if(shapeColor.Length>0)
{
//Assign a new color
var newColor=Random.Range(0,shapeColor.Length);
renderer.material.color=shapeColor[newColor];

}

}

The problem is that the function RespawnWaitTime() doesn´t works… I tried in different ways but with any results. somebody knows which is the problem??

Thanks,

in the MakeBox function you need to
yield the RespawnWaitTime function

function MakeBox(){

//Store an initial position
var position=Vector3 (posx,posy,0);
//Wait some seconds before create a new box
yield RespawnWaitTime();
//Create a new Box with an initial position
Instantiate(Box,position,transform.rotation);
}

that is if you are trying to wait for 3 sconds before instantiating the box.

Ivkoni, I did what you said but it still not working , I replace the function…
I don´t know what happen… I have to have something wrong :frowning:

thanks for your help

Hi I could be barking up the wrong tree here but i know when i use wait for seconds in c# when ever i call the function i have to use startcorutine(MakeBox());
not sure about javascript but i would check that.

Hope it helped

thanks i will tried.