- Edited
Scripting Animation
I just started using Spine today and was curious as to if there are any tutorials on how to script animations in unity?
I currently have two animations for one character: run and jump. I was able to import into unity and get the running animation to work. Now I am trying to script the jump animation to the space key and I'm having the hardest time trying to get it to work. Here's what I have:
private SkeletonAnimation skeletonAnimation;
void Start () {
skeletonAnimation = GetComponent<SkeletonAnimation> ();
}
void Update () {
if (Input.GetKey ("space")) {
skeletonAnimation.state.SetAnimation("jump");
}
}
That should work but you might want to change Input.GetKey to Input.GetKeyDown as the way you have it now every update it's firing whenever the space bar is pressed down so as long as you hold down the jump button it's resetting the animation.
Also you seem to be missing some values for your SetAnimation call. It should be more like:
skeletonAnimation.state.SetAnimation(0, "jump", false);