I got a bug, every time the player moves to the right(D) it keeps moving , when the key is pressed ,untip the left key(A) is pressed, but if The right key is pressed again the player kepps moving to the left. Same thing happens with up and down
//Up
if (Input.GetKey(KeyCode.W))
{
moveY = 1.0f;
}
//Right
if (Input.GetKey(KeyCode.D))
{
moveX = 1.0f;
}
//Left
if (Input.GetKey(KeyCode.A))
{
moveX = -1.0f;
}
//down
if (Input.GetKey(KeyCode.S))
{
moveY = -1.0f;
}
rb.velocity = new Vector2(moveX, moveY).normalized * moveSpeed;
//stop if no key is pressed
if (Input.GetKeyUp(KeyCode.S) || Input.GetKeyUp(KeyCode.W)|| Input.GetKeyUp(KeyCode.A) || Input.GetKeyUp(KeyCode.D))
{
moveX = 0f;
moveY = 0f;
}