Ok, after years of working with ActionScript 3 I got used to use Greensocks superb tweening library “TweenMax” a lot. In my opinion one of the most useful functions is the “delayedCall” method which lets me execute code with some delay (who would have guessed it).

TweenMax (AS3):
TweenMax.delayedCall(2, launchRocket);

Invoke (C#):
I was looking for a “one-liner” to do the same thing in Unity3D using C#. And I found it. It’s called “Invoke” and it’s a method of the MonoBehaviour class which all C# scripts inherit from if they are created within Unity3D.

Invoke("launchRocket", 4);
// triggers the method "launchRocket" after 4 seconds

InvokeRepeating (C#):
To do repeating calls use “InvokeRepeating” and add an additional parameter to set the delay between each call.

InvokeRepeating("launchRocket", 4, 0.5);
// triggers after 4 seconds and does another calls every 0.5 seconds

CancelInvoke (C#):
To cancel use “CancelInvoke” with the method name as parameter. If you want to cancel all invoke calls on a MonoBehaviour don’t pass any name.

CancelInvoke("launchRocket");
//cancels all invoke calls with the given method name

CancelInvoke();
//cancels all invoke calls on the current MonoBehaviour