Answer the question
In order to leave comments, you need to log in
Why doesn't the direction change?
Hello, there is a script that changes the animation depending on the button pressed, but if you hold down one button and then press the second one, with a different direction, it does not change. How to fix it? The code is below.
Thanks in advance for your reply
private void Update()
{
MovementLogic();
}
private void MovementLogic()
{
float horizontal = Input.GetAxis("Horizontal");
float vertical = Input.GetAxis("Vertical");
PlayerMove(horizontal, vertical);
ChangePlayerDirection();
PlayerWalking(horizontal, vertical);
}
private void PlayerMove(float hor, float ver)
{
movementVector.x = hor * playerSpeed * Time.deltaTime;
movementVector.y = ver * playerSpeed * Time.deltaTime;
characterController.Move(movementVector);
}
private void ChangePlayerDirection()
{
if (Input.GetKey(KeyCode.A))
{
animator.SetBool("isLeft", true);
animator.SetBool("isRight", false);
}
else if (Input.GetKey(KeyCode.D))
{
animator.SetBool("isRight", true);
animator.SetBool("isLeft", false);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question