Trouble with last key pressed / direction facing

Hi! I’m making a top down game and I’m having trouble setting animations for different Idle positions.

The Idle animation depends on where my character is facing, this is the code I’ve tried so far, but it resets to the first animation instead of actually where it is facing:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Move2D : MonoBehaviour
{

    public Animator animator;
    public Rigidbody2D rb;

    Vector2 movement;
 
    public float moveSpeed = 0.05f;
    public float objectUsed;
    public float moveDirection;

    void Start()
    {
    //Get the animator
        animator  = this.gameObject.GetComponent<Animator>();
    }

// Update is called once per frame
    void Update(){
        movement.x = Input.GetAxisRaw("Horizontal");
        movement.y = Input.GetAxisRaw("Vertical");

        animator.SetFloat("Horizontal", movement.x);
        animator.SetFloat("Vertical", movement.y);
        animator.SetFloat("Speed", movement.sqrMagnitude);
  
        if (Input.GetKeyDown ("up")) {
            animator.SetFloat("moveDirection", 0);
        }if (Input.GetKeyDown ("right")) {
            animator.SetFloat("moveDirection", 1);
        }if (Input.GetKeyDown ("down")) {
            animator.SetFloat("moveDirection", 2);
        }if (Input.GetKeyDown ("left")) {
            animator.SetFloat("moveDirection", 3);
        } else{
         }

         Debug.Log(moveDirection);
    }

    void FixedUpdate()
    {
        rb.MovePosition(rb.position + movement * moveSpeed * Time.fixedDeltaTime);
    }
}

I’ll also paste my blend tree with the conditions to check for direction and select the animation.

you can rotate your character so your idle animation plays in the right direction, or i’m afraid you’ll need 4 idle animations

I use something like this:
Animator_var.SetFloat(“Horizontal”, moveVector.x);
Animator_var.SetFloat(“Vertical”, moveVector.y);
Animator_var.SetFloat(“Movement”, moveVector.sqrMagnitude);
if (InputVector.sqrMagnitude > 0)
{
Animator_var.SetFloat(“PrevH”, moveVector.x);
Animator_var.SetFloat(“PrevV”, moveVector.y);
}
And the idle animations are a blend tree using PrevH and PrevV just like how the move animations use Vertical and Horizontal. Like Primoz said, you’re probably will need different idel animations for each direction.