How do i tell a script to disable itself?

How do i tell a script to disable itself if my player is outside a certain range, say 10 meters or whatever it is?

heres the script:

using UnityEngine; using System.Collections;

public class EnemyAI : MonoBehaviour { public Transform target; public int moveSpeed; public int rotationSpeed; public int maxDistance;

private Transform myTransform;

void Awake() {
    myTransform = transform;    
}

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

    target = go.transform;

    maxDistance = 2;

}

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

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

    if(Vector3.Distance(target.position, myTransform.position) > maxDistance) {
    //Move towards target
    myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
    }
}

}

At the top of Update:

if ((transform.position - target.position).sqrMagnitude > maxDistance*maxDistance) enabled = false;

using sqrMagnitude as it saves doing a costly square root, feel free to change it to Vector3.Distance(transform.position - target.position) though if you prefer