how to make GUI move with game objects

Does anyone know of a way to link the GUI to follow the transforms of a particular game object?

For instance, if I present a multi-part object with GUI boxes placed over each sub-object, and the larger, main object has an orbit/zoom/pan script already assigned to it, how can I make the GUI move with each of its corresponding constituents?

where can I start looking for how to do this - any directions to documentation would be greatly appreciated!

thanks.

Look into WorldToScreenPoint.

–Eric

Thanks Eric.
If you have a minute, can you take a look and see what I may be doing wrong here…

I have a GO with a camera script attached to the Main Camera allowing it to rotate, pan, zoom around the object.

To make the GUI move in tandem with the rotate,pan,zoom functions, I have created another camera set to depth only, with the GUItext GO as the target, and have attached the aforementioned Main Camera’s script as well as the following script to it:

var target : Transform;


function Update () {
var screenPos = camera.WorldToScreenPoint (target.position);

}

What am I doing wrong here? do I need to add the potential transform coordinates to the target.position (and if so…how)?

I could not find a lot of information on WorldtoScreenPoint besides the small amount that was in the scripting reference, so if you could direct me somewhere else too, that’d be great. The forums had more complex versions of this, I think. :sweat_smile:

never mind - I got it to work with some help from the Unify page and chat room. here’s the script if anyone’s interested:

var healthBarWidth : int;
var healthBarHeight : int;
var healthBarTexture : Texture2D;
var screenPosition :  Vector3;

function Update (){
	screenPosition = Camera.main.WorldToScreenPoint(transform.position);
	screenPosition.y = Screen.height - screenPosition.y;
}

function OnGUI (){	
	GUI.Button(Rect(screenPosition.x - healthBarWidth/2, screenPosition.y - healthBarHeight/2, healthBarWidth, healthBarHeight),"femur");	

}

far from what I started off with, :shock:

or, for a label:

var screenPosition :  Vector3;

function Update (){
	screenPosition = Camera.main.WorldToScreenPoint(transform.position);
	screenPosition.y = Screen.height - screenPosition.y;
}

function OnGUI (){	
	GUI.Label(Rect(screenPosition.x, screenPosition.y, 50, 20),"femur");	

}

function OnGUI (){
GUI.Label(Rect(screenPosition.x, screenPosition.y, 50, 20),“femur”);

What is “femur”

‘femur’ is the label. It’s a type of bone in the leg. :slight_smile:

So you are attaching the text area to the femur within a biped?

I was attaching the label “femur” to the game object called femur. It’s not part of a biped, but is the child of a larger game object (the hindlimb).

And shegmann - thanks for your input girl…have you been drawing a lot of femurs lately?