- Home /
Declaring animations on a script in the editor
Hi all! I currently have a script that will be used for many different characters in the game, but they all use different animations, which is the only thing that would necessitate the need for different scripts. Is there any way to set up public Animation variables which I can assign the necessary animations in the editor for each character?
Something like
var sleepAnimation : Animation;
I've tried this and AnimationState as well to no avail.
Is there any way to do this?
Thank you for your time.
You can't just set the default/idle animation in the animation component within the inspector and run that on start?
Answer by john-essy · Sep 19, 2012 at 11:16 AM
For a start i would have all animations use the same name this way you can create a manager to handle this. I would have an array of animations if there where more than ten or so, So that my inspector didn't look crazy with loads of variables.
After that i would then know that Idle, is = [0] in the array, walk = [1] in the array and so on.
So i would have this
AnimationClip[] animations
Then to call one of those animations i would say something like
if(player.speed <= 0.1)
{
animation.CrossFade(animations[0].name);
}
This way i can create a one size fits all script. (For somethign with the same animations ;))
Awesome! That's exactly what I needed. Thank you so much!
Your answer
Follow this Question
Related Questions
How to split animations via script in editor 1 Answer
Changing variable from another script 1 Answer
Changing variables in another script 3 Answers
Script variable 1 Answer
Modifying several gameobjects with an editor script? 2 Answers