Playing animation by String

Hi Guys,

I have been trying to play an animation by doing the following:

var animname : String;
var canPlay : boolean;

function Update(){
if(canPlay){
animation.CrossFade(animname);
}
}

I get no errors in the console but at runtime the animation is not played.
I change the animname variable to the name of the animation when different things happen. It just won’t work.
I’d really appreciate it if anyone could help!

I found this link that can serve as reference: http://docs.unity3d.com/Documentation/ScriptReference/Animation.CrossFade.html

Make sure you are calling the boolean in the right place! Hope it helps.

What the error is ? I just tested it and you can call it from string variable,private or public. Probably you have not inputted the string from inspector. Or maybe its something about the crossfade i dont know.

Does your prefab or 3D object in your scene have any animation ?(check inspector)

Are you setting the canPlay variable to true while testing?