- Home /
 
               Question by 
               Broseph1010 · Aug 14, 2018 at 12:28 AM · 
                c#animationanimatorcharacteranimation script  
              
 
              How would I switch between 2 animation states connected to 1 state under input?
I have 2 walking animations, left step and right step. They are connected to 1 state called Walking. I have it so that walking is active if a Speed float parameter != 0. Then I have 2 bool parameters, one LeftStep and one RightStep. I have transitions that make it to where they will activate if their bool is true, and deactivate if it is false. When I run the script, if I move forward, it stays on the RightStep. How can I have it flip between states after each step?
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class AnimatorScript : MonoBehaviour {
 
     public Animator anim;
     public bool leftstep = true;
     public bool rightstep = false;
 
 
     void Start()
     {
 
         anim = GetComponent<Animator>();
 
     }
 
     void Update()
     {
 
         float move = Input.GetAxis("Vertical");
         
         if (move != 0) {
             if (leftstep == true)
             {
                 anim.SetBool("LeftStep", true);
                 anim.SetBool("RightStep", false);
 
                 anim.SetFloat("Speed", move);
                 leftstep = false;
                 rightstep = true;
             }
             if (rightstep == true)
             {
                 anim.SetBool("LeftStep", false);
                 anim.SetBool("RightStep", true);
 
                 anim.SetFloat("Speed", move);
                 rightstep = false;
                 leftstep = true;
             }
         }
     }
 }
 
 
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                