Animation.CrossFade help please

I want to make this line of the script work, but it gives me an error. This is the part of the script

animation.CrossFade( Idle.name, 0.15f);

do I need to make a variable or what?

Idle.name seems to be invalid for this circumstance.

Is your animations name “Idle.name” ?

Go to your Project folder, find the animation, and click it. In your inspector, look for the name, and use

animation.CrossFade ( "Idle", 1.5f ) ; // Change Idle to whatever the name you got earlier.

CrossFade(string, float) takes a string for the first parameter that is the name of the AnimationClip to fade to.

Assuming Idle references an AnimationClip on the Animation, then it should properly fade to it with your code. I would try hard coding the name of the clip first.

animation.CrossFade("Idle");

If that doesn’t work, then make sure that the script this is in is a component of the same GameObject that the Animation is a component of. If the Animation is a component of a parent or child of this script’s GameObject, the animation reference could be null. If there are multiple Animations on the same GameObject, the animation reference could point to a different one.

The second parameter or argument of the CrossFade method is correct. The first argument/parameter needs to be the name of the animation, example:

animation.CrossFade("Run", 0.15f);

or 

animation.CrossFade("Idle", 0.15f);

The animation needs to exist, rather be imported with the model, you call that by it’s name in the first argument either as a literal string or a property that contains the name as a string.