2D movement animation with point and click input

I’m trying to make a simple 2d game where we can move using point and click input, and I have a problem where the character didn’t animated the way I want. I want my character have an animation moving to the left, right, up and down but the animation that started only moving right wherever I click the character to move. if you know how to solve this please let me know, even if it only can be animated to the right and left it’s fine I just need it to animated properly, and I have been looking through the internet and no guide that exactly I needed. Maybe I’m not looking enough but I’m really stuck right now. and here is the code

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

public class PlayerMovement : MonoBehaviour
{
    public float Speed = 10f;
    public Animator animator;
    Vector2 lastClickedPos;
    bool moving;

    private void Update()
    {                     
        if (Input.GetMouseButtonDown(0))
        {
            lastClickedPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            moving = true;
        }
        if (moving && (Vector2)transform.position != lastClickedPos)
        {         
            float step = Speed * Time.deltaTime;
            transform.position = Vector2.MoveTowards(transform.position, lastClickedPos, step);
         
            animator.SetBool("isMoving", true);         
        }     
        else
        {
            moving = false;         
            animator.SetBool("isMoving", false);
        }
    }     
}

It looks like this tutorial has all you could ever want :slight_smile: