wait for seconds(), or something else...

Hi there,

In one of my co routines, I pause for a second using yield WaitForSeconds(1), but I’d also like to be able to interrupt that yield (say if the player wants to rush through that section or something).

I guess I need something like this (Imaginary code)

yield WaitForSeconds(1) || while (interrupt == false)yield;

I’m sure there must be something pretty simple that I’m overlooking.

Any ideas?
Thanks
Pete

Well, it just means you’ll have to mimic WaitForSeconds to be able to combine it with your own clause:

var duration = 1.0;
var startTime = Time.time;
while (Time.time - startTime < duration  !interrupt)
    yield;

(untested)

If you use StartCoroutine with a function that uses WaitForSeconds, then you can use StopCoroutine to cancel it.

–Eric

Indeed, but an interrupt like this can be useful when a Coroutine needs to do something else before it is done.

Yes I’d like to have the script continue through after being “interrupted”.
I was thinking of doing something like that but I thought there might have been some easy way I was missing out on.

Thanks
Pete