- Home /
Yielding for a changing amount of time?
I need to yield WaitForSeconds (amount) but that amount may change over time. Is there a way to yield for a dynamic "amount" instead of yielding for the original value?
Thanks in advance!
Answer by Eric5h5 · Mar 26, 2013 at 09:31 PM
You could make a coroutine use a global time variable, then change that variable elsewhere if needed:
var waitTime : float;
function Wait (time : float) {
waitTime = time;
var t = 0.0;
while (t < waitTime) {
t += Time.deltaTime;
yield;
}
}
So that works like WaitForSeconds, except changing the waitTime variable will change the time it waits for, as long as the function is still running.
Answer by jmatthews · Mar 26, 2013 at 09:31 PM
Your question example will damn near compile on its own. Where amount is a float variable and you change its value to whatever you need.
If you need only have the method fire after something else has occured then consider using an event to fire when the method needs to be called.
Your answer
Follow this Question
Related Questions
How to delay a function (how to use WaitForSeconds() and yield) 1 Answer
Boost Script Time problems 1 Answer
Temporarily disable blayer movement? 1 Answer
Waitforseconds vs Time 2 Answers
(c#) Problems with yield 1 Answer