- Home /
Constant Yield Time
So I've currently got a game set up which calls a function via fixed update for a simple yield WaitForSeconds(1) for the reload time.
Now when I launch it on a very fast computer on the lowest settings, the reload time is much shorter than launching it on a slow computer on the max settings.
How do I go about having a constant reload time?
Thanks!
Did you wrote function in which you call yield WaitForSeconds(1); with IEnumerator in front of function name?
Answer by aeroson · Apr 05, 2015 at 12:39 PM
You will most likely never get same results on those two edge-case scenarios.
The way i do reload is:
float reloadDoneIn = 0;
void StartReload() {
reloadDoneIn = 1.0;
}
void Update() {
if(reloadDoneIn>0) {
reloadDoneIn-=Time.deltaTime;
if(reloadDoneIn<=0) {
ReloadDone();
}
}
}
This gives me more control, might be cleaner and more reliable than yield WaitForSeconds. And it does exactly the same thing.
So will Time.deltaTime be a larger interval on a slower computer?
Correct. "The time in seconds it took to complete the last frame (Read Only). Use this function to make your game frame rate independent."
So what time setting (Update $$anonymous$$ode) should I set my animations to, to be able to keep up with the deltaTime?
http://docs.unity3d.com/ScriptReference/AnimatorUpdate$$anonymous$$ode.html Whatever suits your needs, iam using normal mode most of the time.
Your answer
Follow this Question
Related Questions
Time.deltaTime not consistent over time 1 Answer
Updating an array indices dynamically 2 Answers
Execute code every x seconds with Update() 4 Answers
Execute code for a certain amount of time 1 Answer
Pause button 2 Answers