Been following UnityGems for a while - in Coroutines++ - they wrote an example of a WaitForAnimation method - here;
//Wait for an animation to be a certain amount complete
IEnumerator WaitForAnimation(string name, float ratio, bool play)
{
//Get the animation state for the named animation
var anim = animation[name];
//Play the animation
if(play) animation.Play(name);
//Loop until the normalized time reports a value
//greater than our ratio. This method of waiting for
//an animation accounts for the speed fluctuating as the
//animation is played.
while(anim.normalizedTime + float.Epsilon + Time.deltaTime < ratio)
yield return new WaitForEndOfFrame();
}
Here’s what’s keeping it a mystery to me: why did we add float.Epsilon and Time.deltaTime to the while condition? - wouldn’t it suffice if we just said while (anim.NormalizedTime < ratio) - it would make more sense.
in their downloadable project files scripts - they wrote the condition like this:
while(anim.normalizedTime + float.Epsilon < ratio)
I know that float.Epsilon is the smallest float - used to compare if 2 floats are reasonably the same - but why is it used here?
why did they get rid of Time.deltaTime? - thanks guys.