- Home /
Assigning a variable to animation
I like being able to assign what scripts,models,etc to use for a model in the inspector. to do this I would use something similar to this: var x : GameObject;
or
var x : int;
I was wondering how would I assign an animation to it. So something like this: var x : Animation
this is all in JS
Answer by 767_2 · Sep 22, 2014 at 09:41 PM
you can make animation component and animation clip both
var animComponent : Animation;
var animClip : AnimationClip;
animComponent.CrossFade(animClip.name);
you got the animation component and the script on the same gameobject,right
Answer by pgomes · Sep 22, 2014 at 11:57 PM
An alternative solution is to create an AnimationController with the animations you might use and possible transitions. In code, instead of referencing AnimationClips, you can activate triggers:
http://docs.unity3d.com/ScriptReference/Animator.SetTrigger.html
I find this approach easier to debug since you have access to the Animator view and can visualize transitions and the currently active animation.
Your answer
Follow this Question
Related Questions
How to write "if (var int = var int 2)" ? 1 Answer
Cannot convert 'callable(int) as float' to 'float'. 1 Answer
Object to int 1 Answer
c# convert int to string 2 Answers
Having a GUI text as a int 3 Answers