Player sprint problem, only sprints to the right. 2D

Hi there. I have made this script and now i want the player to sprint if the LeftSHift key is pressed. It kinda works. But it can only sprint to the right and not to the left. If the player walks to the left and i press Shift. It will stop moving because it wants to move to the right. I hope someone can help me with this. Here is the script:

using UnityEngine;

using System.Collections;

public class Player : MonoBehaviour {
	
	public float maxSpeed = 5;
	public float speed = 7f;
	public float JumpPower = 150f;
	public float sprint = 7f;

	public bool grounded;

	private Rigidbody2D rb2d;
	private Animator Anim;

	
	void Start () 
	{
		rb2d = gameObject.GetComponent<Rigidbody2D>(); 
		Anim = gameObject.GetComponent<Animator> ();
	}

	void Update () 
		//Animaties, jump en oost/west rivhting kijken/bewegen.
	{
		Anim.SetBool("Grounded",grounded);
		Anim.SetFloat ("Speed", Mathf.Abs(Input.GetAxis("Horizontal")));

		if (Input.GetAxis ("Horizontal") < -0.1f) 
		{
			transform.localScale = new Vector3(-1, 1, 1);
		}
		
		if (Input.GetAxis ("Horizontal") > 0.1f) 
		{
			transform.localScale = new Vector3(1, 1, 1);
		}

		if (Input.GetButtonDown ("Jump") && grounded) 
		{
			rb2d.AddForce(Vector2.up * JumpPower);
		}
	}

	void FixedUpdate()
	{
		Vector3 easeVelocity = rb2d.velocity;
		easeVelocity.y = rb2d.velocity.y;
		easeVelocity.z = 0.0f;
		easeVelocity.x *= 0.75f;

		//moving player
		if(Input.GetKey(KeyCode.D))
		{
			transform.Translate (Vector2.right * speed);
		}

		if(Input.GetKey(KeyCode.A))
		{
			transform.Translate (-Vector2.right * speed);
		}

	//Sprinten
		if (Input.GetKey (KeyCode.LeftShift)) 
		{
			transform.Translate (Vector2.right * speed);
		}
		else if (Input.GetKey (KeyCode.LeftShift)) 
		{
			transform.Translate (-Vector2.right * speed);
		}


		//fake friction / easing the x speed of the player
		if (grounded)
		{

			rb2d.velocity = easeVelocity;

		}

		//limiet player speed
		if (rb2d.velocity.x > maxSpeed) {
			rb2d.velocity = new Vector2 (maxSpeed, rb2d.velocity.y);
		}

		if (rb2d.velocity.x < -maxSpeed) 
		{
			rb2d.velocity = new Vector2(-maxSpeed, rb2d.velocity.y);
		}
	}
}

The problem is under: //sprinten (dutch)
Does someone know the problem here? Thanks for reading! :slight_smile:
And it is a 2D game. And the player can only move to the left and right. Not up and down.

if (Input.GetKey (KeyCode.LeftShift) && Input.GetKey(KeyCode.D))
{
transform.Translate (Vector2.right * speed);
}
else if (Input.GetKey (KeyCode.LeftShift) && Input.GetKey(KeyCode.A))
{
transform.Translate (-Vector2.right * speed);
}

If you hold left shift, you’re telling it to translate right, it never hits that other else if because there’s no scenario where you would hold LeftShift and the else if would execute since the first if statement always would execute. On top of that, you may want to venture away from Translation as your primary form of movement, as it can create nightmares for collisions.

if (Input.GetKey (KeyCode.LeftShift))
{
speed = 10f; //put here your sprint speed

         }else{
             speed = 7f; //put here your normal speed
}

this will work fine :smiley: