- Home /
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!
Answer by mmangual_83 · Jan 02, 2014 at 01:19 PM
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.
Answer by YoungDeveloper · Jan 02, 2014 at 01:27 PM
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.
Answer by sath · Jan 02, 2014 at 03:35 PM
Does your prefab or 3D object in your scene have any animation ?(check inspector)
Are you setting the canPlay variable to true while testing?
Your answer
Follow this Question
Related Questions
Crossfade between an animation and a look at: How to? 0 Answers
Animator.CrossFade or Animator.CrossFadeInInFixedTime does not play animation after crossfading. 0 Answers
Will caching strings improve performance for animation? (and other string calls) 1 Answer
How to stop animated character returning to starting position after animation is complete 3 Answers
Is it possible to crossfade into another section of the same animation? 2 Answers