• Unity
  • Change Skin and Animation in Runtaim

  • Изменено
Related Discussions
...

Hello. Help with advice. I created a character with two Skins, each with two animations. Idle and Walk. In the first the character has an active Idle, in the second Walk. How to switch skins and animations from the code correctly?

Thank. I will read it.


Thank. The problem has been resolved.

using Spine.Unity;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AnimState : StateMachineBehaviour
{
public string animationName;
public string skinName;
public float speed;

override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int LayerIndex)
{
    
    SkeletonAnimation anim = animator.GetComponent<SkeletonAnimation>();
    anim.initialSkinName = skinName;
    anim.Initialize(true);
    anim.state.SetAnimation(0, animationName, true).TimeScale = speed;
    
}

}

Glad you've figured it out, thanks for letting us know.