C# how do i make my enemy stop at a distance? C#

i have been using this script(shown below) but i haven’t been able to figure out how to get the enemy AI to stop close to me but not on me…
this is the script

using UnityEngine;
using System.Collections;

public class enemyAI : MonoBehaviour {

	 public Transform target;
    public int moveSpeed;
    public int rotationSpeed;

    private Transform myTransform;

    void Awake(){
        myTransform = transform;
    }

	// Use this for initialization
	void Start () {
        GameObject go = GameObject.FindGameObjectWithTag("Player");

        target = go.transform;

	}
	
	// Update is called once per frame
	void Update () {
        Debug.DrawLine(target.position, myTransform.position, Color.yellow);

        //Look at target
        myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed * Time.deltaTime);

        //Move toward target
        myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
	}
}

PLEASE HELP ME SOON

GREATLY APPRECIATED GUYS

use Vector3.Distance and define a variable that holds the minimum distance between you and your enemy.

var mindistance = 1.0f;
if(Vector3.Distance(target.transform.position, transform.position > mindistance) {

myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
}

untested but its the general idea

also i think the My Transform variable is kinda unnecessary since you are directly editing it anyway

By the way you should read up on Vectors and Quaternion they have some awesome functions you can use especially since your new here.(as boring as the docs may sound, they are extremely important)

Use Vector3.Distance to get the distance between your transform and the enemies transform, if the distnace is less than your chosen threshold amount stop moving the enemeny

//pseudo code
if(Vector3.Distance(mytransform, theirTransform) > distnaceToStopAt){
    //Move toward target
    myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
}