How to stop checking the distance between objects

Hello,

I have this script that checks when the enemy is close to the player and if it is it takes away some health, here it is
#pragma strict

var Health = 100;
var Enemy : Transform;
var MoveSpeed = 4;
var AttackRange = 1;
var MinDist = 0;

function Start () {

}

function Update () {
     if(Vector3.Distance(transform.position,Enemy.position) >= MinDist){
     transform.position += transform.forward*MoveSpeed*Time.deltaTime;
            if(Vector3.Distance(transform.position,Enemy.position) <= AttackRange)
             {
             	Health -= 1;
           	               //Here Call any function U want Like Shoot at here or something   
             }         
if (Health <= 0) {
	Health = 0;
}

if (Enemy == null) {
			
}

}

}

function OnGUI () {
	 GUI.Label (Rect (10, 10, 100, 20), "Health = " + Health);
}

but my problem is that when i destroy the Enemy it filles the console with messages saying "the object of type transform has been destroyed but you are still trying to access it. how would i stop trying to access it?

Thanks,
Joseph

Check to see if the enemy variable is not null first :

function Update () {
    if ( Enemy != null ) // this can also be written as : if ( Enemy )
    {
        // ....

if (Enemy == null) {
return;
}

put this code on first line of the Update Function; and put this code when you destroying Enemy Object

//Destroy(Enemy);
Enemy = null;

when you destroy object enemy it’s counts in script as missing object and not able to find reference in gamescene