2D RPG AI random movement to chasing, scripting trouble shooting

Guys and Gals, I’ll be straight up I’m really bad at programing, iv only been at it a while and its mostly copying code from you tube tutorials and altering them to suit my needs.
I’m looking to get an enemy to wonder randomly and then when the player is close turn and follow them. but I’m having fierce trouble with getting it to move properly and play the animations for the directions its moving.
Its for an 2D Rpg.
If someone could help me a little that would be great :slight_smile:

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

public class SkeletonControllerAI : MonoBehaviour {

    public Transform[] patrolPoints;
   
    Transform currentPatrolPoint;
    int currentPatrolIndex;

    public Transform target;
    public float chaseRange;

  
    public float awarenessRange;
    public float distanceToTarget;

    private Animator anim;

    public bool playerUp;
    public bool playerRight;
    public bool playerLeft;
    public bool playerDown;

    public float moveSpeed;

    public bool isWalking;

    public float walkTime;
    private float walkCounter;
    public float waitTime;
    private float waitCounter;

    private int WalkDirection; //walk

    private Rigidbody2D myRigidbody;


    // Use this for initialization
    void Start()
    {

        myRigidbody = GetComponent<Rigidbody2D>();

        waitCounter = waitTime;
        walkCounter = walkTime;

        // ChooseDirection();

        anim = GetComponent<Animator>();

    }

    // Update is called once per frame
    void Update()
    {

        //check the distance to the player
        distanceToTarget = Vector3.Distance(transform.position, target.position);

        //check to see if enemy is aware of the player
       /* if (distanceToTarget > awarenessRange)
        {
            ChooseDirection();
        }*/

        //if the player is within the enemys awarenessRange - Chase
        if (distanceToTarget < awarenessRange)
        {
            Chase();
        }
        if (distanceToTarget > awarenessRange)
        {
            ChooseDirection();

        }


        if (isWalking)
        {
            walkCounter -= Time.deltaTime;



            //switch statment
            switch (WalkDirection)
            {
                case 0:
                    myRigidbody.velocity = new Vector2(0, moveSpeed);
                    playerUp = true;
                    break;

                case 1:
                    myRigidbody.velocity = new Vector2(moveSpeed, 0);
                    playerRight = true;
                    break;

                case 2:
                    myRigidbody.velocity = new Vector2(0, -moveSpeed);
                    playerDown = true;
                    break;

                case 3:
                    myRigidbody.velocity = new Vector2(-moveSpeed, 0);
                    playerLeft = true;
                    break;

            }
            if (walkCounter < 0)
            {
                isWalking = false;
                walkCounter = waitTime;

            }

        }
        else
        {
            waitCounter -= Time.deltaTime;

            myRigidbody.velocity = Vector2.zero;

            if (waitCounter < 0)
            {
                ChooseDirection();
            }
        }

        anim.SetBool("PlayerUp", playerUp);
        anim.SetBool("PlayerRight", playerRight);
        anim.SetBool("PlayerLeft", playerLeft);
        anim.SetBool("PlayerDown", playerDown);
        anim.SetBool("IsWalking", isWalking);


    }
    public void ChooseDirection()      //walk 
    {
        WalkDirection = Random.Range(0, 4); //Floats never pick the top number. 0-4 = 0,1,2,3.
        isWalking = true;
        walkCounter = waitTime;


    }

    void Chase()
    {
       
   
        Vector3 directionToPlayer = target.position - transform.position;
        transform.Translate(directionToPlayer.normalized * Time.deltaTime * moveSpeed);

        if (directionToPlayer.x < transform.position.x)
        {
            transform.Translate(-moveSpeed * Time.deltaTime, 0, 0);
            playerUp = true;
        }
        if (directionToPlayer.x > transform.position.x)
        {
            transform.Translate(moveSpeed * Time.deltaTime, 0, 0);
            playerRight = true;
        }
        if (directionToPlayer.y < transform.position.x)
        {
            transform.Translate(0, -moveSpeed * Time.deltaTime, 0);
            playerLeft = true;
        }
        if (directionToPlayer.y > transform.position.x)
        {
            transform.Translate(0, moveSpeed * Time.deltaTime, 0);
            playerDown = true;
        }
        transform.Translate(directionToPlayer.normalized * Time.deltaTime * moveSpeed);
    }
}

iv managed to solve some of the problem but the enemy is still moving to fast to the left when chasing the player