Script does not change targets until target dies

I start the game, a unit gets spawned and the target gets selected so that I can kill it. If I do not kill it and a second unit spawns then I want to run out of range of the first one witch is 20Units and then should pick the next unit within 20 Units.

What it currently does is stays on the same target until its dead even if I run 20units away from it.

Also want the target to be acquired only when I am facing the enemy unit.

var damp = 6.0;
var BulletPrefab:Transform;
var bulletSpeed = 1000;

function Update ()
{	
	//Assign Enemy
	var LookAtTarget : GameObject ;
	LookAtTarget = GameObject.FindWithTag("EnemyAI");

	//Calculate Distance from enemy
	var dist = Vector3.Distance(transform.position, LookAtTarget.transform.position);
	if (dist > 20) {
		LookAtTarget = null;
	}

	//Only detect enemy withing range of 20meteres

	//If target aquired then do
	if(LookAtTarget)
		{
			//Rotate Gun
			var rotate = Quaternion.LookRotation(LookAtTarget.transform.position - transform.position);
			transform.rotation = Quaternion.Slerp(transform.rotation, rotate, Time.deltaTime * damp);
			//Aquire Target
			GameObject.FindWithTag("Crosshair").guiTexture.enabled = true;
			GameObject.FindWithTag("Crosshair").GetComponent("TextFollowScript").target = LookAtTarget.transform;
			//Shoot if Fire button pressed
		if (Input.GetButtonDown("Fire1")){	
			var Bullet = Instantiate(BulletPrefab, transform.Find("SpawnPointT").transform.position, Quaternion.identity);
			Bullet.rigidbody.AddForce(transform.forward * bulletSpeed);
		}
	}
	//If no target then do
	if(!LookAtTarget) {
		GameObject.FindWithTag("Crosshair").guiTexture.enabled = false;
	}
	
}

Your script looks for a single GameObject tagged “EnemyAI”, and then immediately discards it if over 20m away. You don’t have any code to look for or consider other enemies in the scene. What you need to do instead is start by seeing if you have a current target; if so, see if it is still in range; if not, discard it. Then you check again if you have a current target and, if not, look for the closest “EnemyAI” object within range. Physics.SphereCast() may help with that final step; if you know you’ll only ever have a small number of enemies alive at one time, you could also brute-force it using GameObject.FindGameObjectsWithTag() then looking at each returned object to figure out which to target.