animationunity-game-enginespine

How do change Spine animations in Unity?


I have a conditional if then statement running where I want the animations to change if a certain condition is met. For some reason when it starts, the correct animation plays, but when it is changed the animation doesn't change. The code is running in LateUpdate(). I made a hack to test the changing of the animations and it won't work either.

Everything I have read says to use SetAnimation and it will over ride the previous animation, but this doesn't seem to be working. Here is the code to hack that result I want.

rightCrowdMemberAnimation.state.SetAnimation (0, "idle_07", true);

if (Input.GetKeyDown (KeyCode.A)) {

rightCrowdMemberAnimation.state.SetAnimation (0, "yay_07", true);

}

Thanks for the help.

What is weird is that the in the inspector it says that the animation has changed, but visually it hasn't changed.

Note: This is what i was trying to accomplish. It appears that while I was in LateUpdateit was resetting back to the idle when I clicked A. I am still not sure why it won't change the animation under what is below. I thought the A button trick was similar in execution, but I guess I was wrong.

void Start(){
    Assume I did a random roll of color {red,blue,yellow}
}

The real issue is

void LateUpdate(){
     if (color = red) {
         rightCrowdMemberAnimation.state.SetAnimation (0, "idle_07", true);
     } else if (color = blue) {
         rightCrowdMemberAnimation.state.SetAnimation (0, "idle_08", true);
     } else if (color = yellow){
         rightCrowdMemberAnimation.state.SetAnimation (0, "idle_09", true);
     }
}

In the inspector the animation I want to show up is there. Just the animation that I am calling isn't showing up.


Solution

  • Basically you have to change property AnimationName on SkeletonAnimation script. Here is sample:

    private SkeletonAnimation skeletonAnimation;
    
    void Awake()
    {
        skeletonAnimation = GetComponent<SkeletonAnimation>();
    }
    
    void LateUpdate(){
         if (color = red) {
             skeletonAnimation.AnimationName = "idle_07";
         } else if (color = blue) {
             skeletonAnimation.AnimationName = "idle_08";
         } else if (color = yellow){
             skeletonAnimation.AnimationName = "idle_09";
         }
    }