yield; Before LateUpdate()

Anyone have a work around for this?

I simply want to:

var delayTime : float = 2.0;

yield new WaitForSeconds(delayTime);

function LateUpdate() {

// do code

}

Thanks

-Raiden

This makes no sense.
Outside of functions you can only declare things, not execute.

Especially you can not delay any callback function. Wouldn’t make sense anyway as the function will be called again after the next update round, independent if the previous one has finished or not, so you would end with about 120 pending LateUpdate functions with a 2s wait time.

I guess what you are trying to do is not having a lateupdate in the first 2 seconds or alike?
In that case use a variable to store the current time.
set that variable in Start
And check if the time difference from now and that time holding variable is larger than 2. if not, just return

You can execute code outside of functions in JS. Any statement outside of a function declaration is executed in Main(), which is called after all objects’ Awake() and before that object’s Start().

Anyway, to the OP’s question. Just do:

private var doWhatever:boolean = false;

function Start()
{
   yield WaitForSeconds(2.0);
   doWhatever = true;
}

function LateUpdate()
{
   if(doWhatever)
   {
       // do your stuff
   }
}

Thank you both for the replies.

@dreamora

I understand what your saying, I failed to closely examine the “yield” statement in the docs, which I thought were the way I had it, thanks for pointing it out.

@Matthew, thank you for the code example, was just what I needed.

-Raiden