How to get a prefab to look at a target?

I’m trying to get an enemy to look at a target, but I can’t get it to work. I tried using this too:

var target : Transform;

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

But I can’t set the value of “target” because the enemy is a prefab! Is there anyway to set the value of target in the script? I tried using this:

var target : Transform;

function Update () {

target = GameObject.Find("I put the name of my target here");

transform.LookAt(target);
}

But I can’t use that because it can’t convert a GameObject to a transform. I also tried using “transform.Find” but that didn’t work either. Thanks in advance! (P.S. I’m using unity 3.5)

I think what you’re looking for is transform.LookAt(target.transform), unless it’s done differently in JS than c#.

Transform is a property of GameObject, which you’re actually already invoking for the local object when you call gameobject.transform.LookAt (although you can omit gameobject when it’s called on a script that is attached to a gameobject).