J
Jomnitech

  • 24 mai 2020
  • Inscrit 20 mai 2018
  • I`m using Spine with Unity inkluding the Animator tool. For this i use this code:

    public class AnimationScript : StateMachineBehaviour
    {
        public string AnimationName;
        public float AnimationSpeed;
        public bool loop = true;
        public int track = 1;
    
    private SkeletonAnimation anim;
    //OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
    override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        anim = animator.GetComponent<SkeletonAnimation>();
        anim.state.SetAnimation(track, AnimationName, loop).TimeScale = AnimationSpeed;
     
    }
    

    This works well so far. Now im trying to set the TmeScale for the walk animation to the real velocity of the Character.
    I tryed by using:

    public class AnimationScript : StateMachineBehaviour
    {
        public string AnimationName;
        public float AnimationSpeed;
        public bool loop = true;
        public int track = 1;
    
    public bool useRealSpeed= false;
    private float currentSpeed;
    
    private SkeletonAnimation anim;
    //OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
    override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        anim = animator.GetComponent<SkeletonAnimation>();
        anim.state.SetAnimation(track, AnimationName, loop);
    
        if (!useRealSpeed)
        {
            anim.timeScale = AnimationSpeed;
        }
     
    }
    
    override public void OnStateMove(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {    
        if (useRealSpeed)
        {
            currentSpeed = animator.GetFloat("MovementSpeed");
            anim.state.TimeScale = currentSpeed * .5f;
        }
    }
    

    but it mess up the hole timesclae for other Animations too. I`m using two Tracks, 0 for Legs and 1 for Arms and Body.
    Can anyone help me with that?