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?

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 ) ) {