Make a GUIlabel follow an object in space

I used the following Javascript code from the Unity wiki with the intent of creating a GUIText that hovers over the enemy AI that I attach it to. The idea is to show the user the damage incurred by the enemy AI each time the user hits his target.

Rather than staying fixed on the attached object, however, the GUIText stays fixed at the center of the screen, or main camera I’m guessing.

Reading the Usage notes on the wiki, I thought this script was supposed to fix the GUI on the attached object.

I have tried attaching the script to an empty game object, which I have then parented to the game object it’s supposed to follow. The result is that the GUIText stays fixed at the center of the screen rather than on the parent game object.

I have tried attaching the script directly to the game object it’s supposed to follow. The result is that the game object flies off the screen as soon as I hit play.

Any idea what I’m doing wrong?

Thanks in advance.

Here’s the source:
http://wiki.unity3d.com/index.php?title=ObjectLabel

Here’s the code:

var target : Transform;
//Object that this label should follow
var offset : Vector3 = Vector3.up; 
//Units in world space to offset; 	 unit above object by default
var clampToScreen : boolean = false;
//If true, label will be visible even if object is off screen
var clampBorderSize : float = 0.05;
//How much viewport space to leave at the borders when a label is being clamped
var useMainCamera : boolean = true;
//Use the camera tagged MainCamera
var cameraToUse : Camera;
//Only use this if useMainCamera is false
private var cam : Camera;
private var thisTransform : Transform;
private var camTransform : Transform;

function Start () 
{
	thisTransform = transform;
	if(useMainCamera)
			cam = Camera.main;
	else
			cam = cameraToUse;
	camTransform = cam.transform;

}

function Update () 
{
	if(clampToScreen)
	{
		var relativePosition = camTransform.InverseTransformPoint(target.position);
		relativePosition.z = Mathf.Max(relativePosition.z, 1.0);
		thisTransform.position = cam.WorldToViewportPoint(camTransform.TransformPoint(relativePosition + offset));
		thisTransform.position = Vector3(Mathf.Clamp(thisTransform.position.x, clampBorderSize, 1.0 - clampBorderSize), Mathf.Clamp(thisTransform.position.y, clampBorderSize, 1.0 - clampBorderSize), thisTransform.position.z);
	}
	else
	{
		thisTransform.position = cam.WorldToViewportPoint(target.position + offset);
	}
}

@script RequireComponent(GUIText)

You could make it an object of the enemy instead of scripting (depending on the game)