targeting problems

basically i start the game but i have problem with targeting game objects

wondering if anyway can find any problem
the mobs are spawned into the game so would that impact anything?
and what needs to happen is they spawn in and they then select a defense out of the 4 defenses available once it has 0 hp then they move on onto the base but if the character gets in the way it will change to that target

using UnityEngine;
using System.Collections;

public class MobAiEast : MonoBehaviour {

public float preceptionradius = 10;
public float BaseMeleeRange = 4;
public Transform target;
public float Nill = 0;
public Transform _myTransform;
public Transform _east;
public Transform _base;
public Transform _player;
public GameObject East;

public int random;
public GameObject[] Defense;
void Start () {
	random = Random.Range(0, 5);
	
	Defense = GameObject.FindGameObjectsWithTag("east");
	CharacterController cc = GetComponent<CharacterController>();
	
	
	
	if(cc == null) {
		Debug.LogError("no controller");
	}
	else{
		
	}
	 East = Defense[random]; 
	_myTransform = transform;
	GameObject Player = GameObject.FindGameObjectWithTag("player");
	GameObject Base = GameObject.FindGameObjectWithTag("Base");
	_east = East.transform;
	_base = Base.transform;
	_player = Player.transform;
	_east = target;
}

void Update () {
	Defense other = East.GetComponent<Defense>();
	if(other.CurHealth == 0  || other.CurHealth < 0) {
		if(Vector3.Distance(transform.position, _player.transform.position) < 8) {
			target = _player;
		}
		else
			target = _base;
	}
	else
		target = _east;

	if(target){
goes on with moving to target stuff (can ignore i know it works :P)

thanks for any help!

I have here :
http://users.metropolia.fi/~lucasc/AiEnemy.js

an AI script that I think would do what you are looking for.

It is a simplified version as it does not use the CC (it should though…and maybe will later when I have time)

The script has 4 waypoints that are randomly assigned as target. When the NPC reaches a target a new one is given until the player gets inside a range then the player becomes the target until he escapes the range. It is in Js and is pretty simple.

So you shoul dbe able to find what you need.