- Home /
Invoke Repeating Rate
Hi,
i have this code:
InvokeRepeating("SetTime", 0, timeSpawn);
and i have the timeSpawn variable changing, so i need this to be dynamic. What i find out is that i cant directly change rate of invoke like this as it is called only once.
Is there some way around it ? I read here about using yielding for this. But i kind of struggle with it. Is there any solution to have dynamic invoke repeating ?
thanks
Luke
Answer by Waz · Jul 12, 2011 at 12:12 PM
Just write the code manually as a co-routine:
function SpawnStuff()
{
while (true) {
SetTime();
yield WaitForSeconds(timeSpawn);
}
}
Then just call that function to start it invoking, just as you currently do with InvokeRepeating.
No need to fear coroutines.
This answer is overly vague (as is most of the answers here). So SetTime(); is not a function monodevelop found. What is this? timespawn is a float number variable, I get that. Anyone?
Also, the (true), I am assu$$anonymous$$g that while this is true, this keeps repeating. How do you set it to false? I'm a newbee, sorry.
SetTime() is a function oliver344 using in his/her own program, it has nothing to do with $$anonymous$$onoDevelop. Using "while(true)" means it will stays true til the end of the time. Of course you can change "true" to anything else you need. It really depends on what you're trying to achieve.
Your answer
Follow this Question
Related Questions
Why does this not work? 1 Answer
Invoke.Repeating doesn't really "care" about repeat time? 1 Answer
Invoke/yield in non MonoBehaviour classes 1 Answer
InvokeRepeating affecting parts of script 1 Answer
How to Invoke() .. one frame 2 Answers