Create a vector between me and my enemy.

Hello everyone, i’m working on a plane game and i want my enemy to attack me when is a certain distance from me, since i’m shooting bullets as well i can’t use a sphere trigger collider around me because my bullets hit that collider so i was thinking using a vector traced from my enemy position to me and everytime it was shorter than a certain distance it would start shooting me. The question is, how do i create this vector keeping it updating?

I’m using this condition to shoot:

var bulletPrefab: Transform;
var bulletSpeed = 60;
var nextShotTime : float = 0.0;
var timeBetweenShots : float = 2.0;
//var shootSound: AudioClip;

function Update()
{
	if (***********)) //this is where my vector condition would enter
	{
//		Shoot();
		if (nextShotTime <= Time.time)
          {
              Shoot();
              nextShotTime = Time.time + timeBetweenShots;
		}
	}	
			
}


function Shoot()
{
    var shoot = Instantiate(bulletPrefab,GameObject.Find("Spawn").transform.position,GameObject.Find("Spawn").transform.rotation);
			shoot.rigidbody.AddForce(GameObject.Find("Spawn").transform.forward * bulletSpeed);
//	AudioSource.PlayClipAtPoint(shootSound, GameObject.Find("Spawn").transform.position);
}

Can you guys help me out with this, doesn’t seem very complicated but i really can’t figure it out… Thanks everyone.

I assume this is the enemy script. You need the game object of the player (or the transform). Typically you would get this once at Start();

var goPlayer : GameObject;

function Start() {
     goPlayer = GameObject.Find("Player");
//alternate goPlayer = GameObject.FindWithTag("Player");
}

Then in update you can test the distance:

if (transform.position - goPlayer.transform.distance).magnitude < someValue) {
   // Shooting stuff
}