Enemy Ai Improvement!

i have created a enemy ai that is supposed to make the object move back to a defined position when there is a hostile projectile closeby.

var target : Transform;
var avoidTreshold = 10;
private var avoiding = false;
var MyTransform : Transform;

function Start ()
{
     var target = gameObject.Find("Bullet").transform;
}

function Update () 
{
	 var dist = (target.position - MyTransform.position).magnitude;
	 
	 if(dist > avoidTreshold)
	 {
	     avoiding = false;
	 }
	 
	 if(dist < avoidTreshold)
	 {
	     avoiding = true;
	 }
	 
	 	 if(avoiding)
	 {
	     transform.gameObject.Find("AvoidPosition");
	 }
}

But when i try it out i get an error message saying :

NullReferenceException
EnemyAvoid.Start () (at Assets/EnemyAvoid.js:8)

Can anyone help me out?

function Start ()
{
     var target = GameObject.Find("Bullet").transform;
}

GameObject should be capitalized. If you are searching through children, use transform.Find()

Is the “Bullet” object supposed to exist at all times? I’d guess not, and if that’s the case, your call the “Find” will fail when there is no Bullet object. Once the Find fails, everything you have above falls apart.

Ok thanks for the help but how am i supposed to make it find the target if it’s only a prefab?