- Home /
Is "Invoke" just a short version for "yield WaitForSeconds" + FunctionCall?
Found this in the FPS-Tutorial, in the DamageReceiver.js: Is
Invoke ("DelayedDetonate", detonationDelay);
the same as:
yield WaitForSeconds (detonationDelay);
DelayedDetonate ();
? Or am I missing some siginficant detail here?
Thanks & Greetz, Ky.
Answer by Stelimar · Dec 07, 2009 at 10:36 PM
The two examples you gave would give identical results. However, if you placed a piece of code afterwards, with Invoke it will get executed immediately, whereas with the yield it will be delayed as well.
For example, with this function, someOtherFunction will be called immediately, and DelayedDetonate will be called after detonationDelay seconds.
function Delay() {
Invoke("DelayedDetonate", detonationDelay);
someOtherFunction();
}
Whereas with this function, DelayedDetonate will be called after detonationDelay seconds, and someOtherFunction will be called right after DelayedDetonate.
function Delay() {
yield WaitForSeconds(detonationDelay);
DelayedDetonate();
someOtherFunction();
}
Also, you cannot pass arguments using Invoke.
Thanks, very helpful, both of you =) HA! Can upvote now! ^^
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
How can I send and receive data to and from a URL, i.e. server side scripts, web services, etc? 3 Answers
Unity Optimization Tips ! 1 Answer
Preloading / Caching Prefabs [Unity iPhone] 4 Answers
how to move between scenes 1 Answer