Integer value wont change In if Statement

This code is for an fps animator and i want to have an idle sprint and walking animations, ive set parameters for the idle to equal 0, walking to 1 and Sprinting to 2 in the animator tool, however the transitions wont play instead nothing happens.
here is the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class movementanimations : MonoBehaviour
{
public Animator animator;

private int movement = 0;

public MovementPlayer Player;

void Update()
{
bool walkingPressed = Input.GetKey(“w”) || Input.GetKey(“a”) || Input.GetKey(“s”) || Input.GetKey(“d”);
bool sprintPressed = Input.GetKey(KeyCode.LeftShift);

if (Player.isGrounded && walkingPressed)
{
movement = 1;
animator.SetInteger(“Movement”, movement);
Debug.Log(“walkingPressed”);
}
else if (Player.isGrounded && walkingPressed && sprintPressed)
{
movement = 2;
animator.SetInteger(“Movement”, movement);
Debug.Log(“Sprinting”);
}
else
{
movement = 0;
animator.SetInteger(“Movement”, 0);
Debug.Log(“idle”);
}
}
}

The debug… print nothing?

Please write the code with the insert code function, so it’s easier to read and help. :slight_smile:

You need to change around your if statement orders. As it is the sprinting will never happen because two of the conditions that go towards it also fulfil the walking check that occurs earlier.
What you have is this:

  1. If the Player is Grounded, and they are pressing the Walk button then do the walking animation
  2. If the Player is Grounded, and they are pressing the Walk button, and they are pressing the Sprint button then do the sprinting animation.

Even if you are pressing the Sprint button it will never trigger that part of the if statement because the rest of the condition is the same as the walking condition.
When you use the same sets of conditions you should always put the one that requires the most checks to occur first, ie:

  1. If the Player is Grounded, and they are pressing the Walk button, and they are pressing the Sprint button then do the sprinting animation.
  2. If the Player is Grounded, and they are pressing the Walk button then do the walking animation

This will work because the sprint will be checked along with everything else, and if they are not using the sprint, then it will check the next if statement which then determines that they are only walking.

void Update()
{
  bool walkingPressed = Input.GetKey("w") || Input.GetKey("a") || Input.GetKey("s") || Input.GetKey("d");
  bool sprintPressed = Input.GetKey(KeyCode.LeftShift);

  if (Player.isGrounded && walkingPressed && sprintPressed)
  {
    movement = 2;
    animator.SetInteger("Movement", movement);
    Debug.Log("Sprinting");
  }
  else if (Player.isGrounded && walkingPressed)
  {
    movement = 1;
    animator.SetInteger("Movement", movement);
    Debug.Log("walkingPressed");
  }
  else
  {
    movement = 0;
    animator.SetInteger("Movement", 0);
    Debug.Log("idle");
  }
}

Please also post scripts using code tags (as I have done above) as this makes it so much easier to read.