Whats going on with these prefabs???

Okay I’ve been chipping at this for days now, posting far too many questions on the forums and Unity answers. I’m having trouble with my enemy, here is the script:

var LookAtThis : Transform;
var elaser : Transform;
var damp = 2;

function Update () {
if(Vector3.Distance(LookAtThis.position,transform.position) < 800){
var rotate = Quaternion.LookRotation(LookAtThis.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotate,damp * Time.deltaTime);
transform.Translate(0,0, 10 * Time.deltaTime);


}

}
InvokeRepeating("fireAtPlayer",1,2);

function fireAtPlayer() {
if(Vector3.Distance(LookAtThis.position,transform.position) < 800){
Instantiate(elaser,transform.Find("espawnpoint").position,transform.rotation);
}
}

function OnCollisionEnter(hit : Collision) {
if(hit.gameObject.tag == ("Player"))
Debug.Log("Watch it!");
}

So I’m trying to make this enemy ship into a prefab but I cant drag a gameObject into the Player var, I did some research and I guess you cant do that unless that gameObject is also a prefab, which seams to make sense. But when I drag a prefab into that var then the enemy will move to the position the player prefab is at game start, but it will not follow the prefab when it moves.
I’ve already established that the script is attached to the correct object of the player.

I’m dying for some help, any kind of tip is greatly appreciated. this doesn’t seam to make any sense.

Rather, they don’t go to where they are on game start, they go to where they were when the prefab was created.

Prefabs have positions. If you’ve dragged the player’s prefab (rather than the actual game object) onto the script, it’ll use the prefab’s position (which isn’t changing since its scripts aren’t running).

Note that I’m using “prefab” and “game object” with specific meanings - a game object exists in the game, while a prefab exists only in the project panel.

Oh I see, so then what steps must I take to get the enemy to follow my player, if I cant drag game objects or prefab instances into prefab scripts, and dragging prefabs into these scripts will give me a dead position, how should I go about getting the proper result?

Probably the easiest way is to tag your player something unique (“player” comes to mind :)) and then have other things find it using that tag -

private var playerTransform : Transform;

function Start() {
  playerTransform = GameObject.FindObjectWithTag("player").transform;
}

I get "Assets/enemy/enemy (attack player).js(31,65): BCE0019: ‘transform’ is not a member of ‘UnityEngine.GameObject[ ]’. " error message, that means that it cant use transform with GameObject right? By the way I appreciate the help :slight_smile: