- Home /
Is it possible to change Invoke Repeating rate on the fly?
Hi,
I have this code, it's pretty self-explanatory:
InvokeRepeating( "InstantiatePlatform", 1 , 6/globalSpeed );
function InstantiatePlatform () {
Instantiate (prefab, Vector3(spawnPoint.position.x, 0, 0), Quaternion.identity);
globalSpeed +=1;
}
Unfortunately, the rate of repeating the function doesn't change. It only takes the first value and continues to instantiate objects at that rate.
When I think about it, it's logical since InvokeRepeating doesn't update, but is there a way to change speed or should I use another method?
Thanx
Answer by Mike 3 · Feb 07, 2011 at 03:31 PM
Check the answer I posted here:
http://answers.unity3d.com/questions/15941/random-range-spawntime/15943#15943
Can somebody re-answer this? The link cannot be found at the moment.
Answer by Kiloblargh · Mar 07, 2012 at 05:44 PM
Since in your case the variable globalSpeed is being set by InstantiatePlatform every time it runs, don't use InvokeRepeating. Just use Invoke. Then have the function Invoke itself again at the end in (globalSpeed seconds).
If something somewhere else were changing the value of globalSpeed, you could check in InstantiatePlatform if globalSpeed has changed since the last time it ran, and if so, CancelInvoke("InstantiatePlatform") and InvokeRepeating again with the new speed.
Answer by rokyed · Jul 26, 2013 at 06:59 AM
Do not use Invoke alone ( it will instantiate your function every single time , wich meakes the whole process go slow , I started with a 78FPS ended with 4FPS only after 20000 times getting invoked . I also tested InvokeRepeating wich does not dumps all the data after and recycles it , so therefor you can do an invoke repeating with 0.01 delay , and use another variable to track the delay manually ... unfortunately not everything comes out of the box , most of it we need to make it.Good day!!
Your answer
Follow this Question
Related Questions
Invoke.Repeating doesn't really "care" about repeat time? 1 Answer
InvokeRepeating doesn't work 2 Answers
Increase speed every 5 seconds 1 Answer
Invoke Repeating Rate 1 Answer
2D Limit player speed 3 Answers