- Home /
Animation.Time help
Why isn't this working with Animation.Time?
var example : GameObject;
example.animation.CrossFade("Cart rolling");
if (example.animation["exampleanim"].time == 0.1)
{
example.animation["exampleanim"].speed = 0;
}
The animation is playing, and I have example defined. What is wrong here?
Answer by Peter G · Sep 11, 2011 at 09:52 PM
It's probably a floating point imprecision issue. You can choose how much tolerance you want to allow in error. This is what Unity has Mathf.Approximately() for. It wouldn't be hard to implement yourself if you wanted to though. Here's an example using Unity's built-in function. To make your own. Take the absolute value of the difference between the two and see if its less than or equal to Single.Epsilon.
if( Mathf.Approximately( example.animation["exampleanim"].time , .1 ) ) {
Tried this: Cart.animation.CrossFade("exampleanim"); if ($$anonymous$$athf.Approximately(example.animation["exampleanim"].time, 0.1)) { Cart.animation["exampleanim"].speed = 0; }
Oh yeah does it make a difference if it's in a GUI button ins$$anonymous$$d of the usual update function?