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?