title: Play animation with Xbox controller
body: <p>I am making a 2d game that can use either the keyboard or an Xbox One controller as movement.</p>
  
  <p>So far, I can move the players and play a running animation, jump animation etc using the keyboard, and I can move using the Xbox controller.</p>
  
  <p>However, I can't play animations with the Xbox controller.</p>
  
  <p>I have this:</p>
  
  <pre><code>void Update()
  {
      movement.x = Input.GetAxis("LeftJoystickX") * speed * Time.deltaTime;
  
              // Orange player movement
              if (orange)
              {
                  transform.position += movement;
  
                  if (Input.GetKey(KeyCode.D))
                  {
                      ChangeDirection("right");
                      ChangeState(STATE_RUN);
                      transform.position += Vector3.right * speed * Time.deltaTime;
                      if (!onGround)
                          ChangeState(STATE_JUMP);
                  }
              }
  }
  </code></pre>
  
  <p>Here, if you use the keyboard, the animations play. If you use the controller, the player moves but the animations don't play. I've <strong>tried</strong> and narrowed it down to the fact that this piece of code will not evaluate:</p>
  
  <p><code>if (Input.GetAxis("LeftJoystickX"))</code></p>
  
  <p>as <code>Input.GetAxis()</code> returns a float and not a bool (?) and therefore cannot be put in an <code>if</code> statement.</p>
  
  <p>I guess what I am asking is, is it possible to detect a direction of a Joystick push from a controller, such as something like <code>Input.GetAxis().joystickPushedRight</code>?</p>
  
  <p>Or better yet, is there a different way I could execute</p>
  
  <pre><code> if (Input.GetKey(KeyCode.D))
          {
              ChangeDirection("right");
              ChangeState(STATE_RUN);
              transform.position += Vector3.right * speed * Time.deltaTime;
              if (!onGround)
                  ChangeState(STATE_JUMP);
          }
  </code></pre>
  
  <p>But use the joystick instead of <code>Input.GetKey</code>?</p>
  
  <p>Thanks!</p>