How to find target the LookAt with a prefab?

Okay i have an enemy prefab that gets spawned by a collider. I want the prefab to look at the player and eventually fire missiles. However, i’ve come across a problem where i can’t attach the player Transform to the prefab so i’m trying to find a way around it by using “Find” or “FindWithTag” however, none are working very well

var player : Transform;

function Start (){
	player = Transform.FindWithTag("Player");
}

function Update () {
	transform.LookAt (player);
}

I’ve tried variations of GameObject, Transform, Component but none are working with each other. Is there another way around this?

You must first make sure the player’s tag is set to “Player” (it’s one of the standard tags). Find the player at Start with this code:

var player: Transform;

function Start(){
    player = GameObject.FindWithTag("Player").transform;
}

FindWithTag is one of the GameObject functions, and returns a GameObject, but you can get its transform like above.