camera.WorldToScreenPoint

function Update(){
var screenPos :Vector3 = camera.WorldToScreenPoint(target.position);
//print (“target is " + screenPos.x + " pixels from the left”);
print (“target is " + screenPos.y + " pixels from the top”);
Positionx = screenPos.x;
Positiony = screenPos.y;
}
function OnGUI (){
GUI.skin = GuiSkin;

GUI.Button (Rect(Positionx,Positiony,100,20),Healthtexture);

}

my problem is my positiony takes from the bottom of the screen and not the top… so the healthbar is not over my gameobject. if my gameobject is 10px from the top… my healthbar is 10px from bottom… any ideas how i can fix this problem?

take the screen height and minus your computed y. that will flip it for you

yea it works ty alot:smile::smile:

heey,
i got this errors:

with this code:
NPC_NAME:

get rid of transform and it might work, that means that your referencing the target an the gameobject that the script is attached to at the same time, which you arent supposed to do.

and also try putting var in front of Positionx and y

if i get rid of the transform in screenPos i get ths error:

change the variable target to Transform

that that gets rid of position error.
but these are still there:
Unknown identifier: ‘Positionx’.
Unknown identifier: ‘Positiony’.
EDIT: Maybe its because the script calls OnGUI first and then Update?

use this

var name1 = "";
var target : Transform;

var Positionx : float;
var Positiony : float;

function FixedUpdate(){
	var screenPos : Vector3 = camera.WorldToScreenPoint(target.position);
	Positionx = screenPos.x;
	Positiony = screenPos.y;
}

function OnGUI (){
	GUI.Button (Rect(Positionx,Positiony,100,20),name1);
}

that does it.
thanks :slight_smile:

Your welcome!!! a lot!!! I am happy to help!!!