- Home /
Question by
Starklndustries · Jan 31, 2020 at 10:35 AM ·
unity 2dmovingrunning
Why does my character move when pressing Lshift but if I dont press it he plays the animation but stays in place?
if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow) && !isDead && !isHurting)
{
rb2d.velocity = new Vector2(runSpeed, rb2d.velocity.y);
if (isGrounded)
{
animator.SetBool("IsRunning", true);
}
Vector3 characterScale = transform.localScale;
characterScale.x = 2;
transform.localScale = characterScale;
}
else if (Input.GetKey(KeyCode.A) && !isDead && !isHurting)
{
rb2d.velocity = new Vector2(-runSpeed, rb2d.velocity.y);
if (isGrounded)
{
animator.SetBool("IsRunning", true);
}
Vector3 characterScale = transform.localScale;
characterScale.x = -2;
transform.localScale = characterScale;
}
else
{
if (isGrounded)
{
animator.SetBool("IsRunning", false);
}
rb2d.velocity = new Vector2(0, rb2d.velocity.y);
}
if (Input.GetKey(KeyCode.LeftShift) && Input.GetKey(KeyCode.D) && !isDead && !isHurting)
{
rb2d.velocity = new Vector2(runSpeedSprint, rb2d.velocity.y);
if (isGrounded)
{
animator.SetBool("IsSprinting", true);
}
Vector3 characterScale = transform.localScale;
characterScale.x = 2;
transform.localScale = characterScale;
}
else if (Input.GetKey(KeyCode.LeftShift) && Input.GetKey(KeyCode.A) && !isDead && !isHurting)
{
rb2d.velocity = new Vector2(-runSpeedSprint, rb2d.velocity.y);
if (isGrounded)
{
animator.SetBool("IsSprinting", true);
}
Vector3 characterScale = transform.localScale;
characterScale.x = -2;
transform.localScale = characterScale;
}
else
{
if (isGrounded)
{
animator.SetBool("IsSprinting", false);
}
rb2d.velocity = new Vector2(0, rb2d.velocity.y);
}
Comment