- Home /
Question by
skate4life13010 · Oct 30, 2014 at 06:39 AM ·
timepausesleep
Timer delay
Im using the OnCollisionExit function which Id like to keep on one script. The other script checks for gameObjects in a scene but it must call each function at exactly the same time. Can i put a quarter second delay to execute code in one of my functions like the sleep() in obj-c?
Comment
Answer by AlwaysSunny · Oct 30, 2014 at 05:08 AM
Not really sure what you're trying to achieve, but when I hear "I want to delay for N seconds" I think corotine:
IEnumerator MyCoroutine() {
// Do something
yield return new WaitForSeconds(5);
// Do something 5 seconds later
yield break;
}
Invoke with StartCoroutine(MyCoroutine()) and be aware that, just like methods, they're called again when invoked, not "overridden" so you may need to set a bool like isBusy while it's waiting.