Hi,
I want to position a health bar over the head of certain characters in my game. I know how to create a health bar but I’m not sure how you would go about getting the coordinates of where the health bar should go.
Can somebody help me?
Thanks,
Rollo357
Im not very good at scripting, but heres a general idea:
var Offset: int = 10; //the distance from the character at which you want the healthbar to be (10 units above or whatever)
For Healthbar:
transform.position = positionOfCharacter + Offset
simply setting the position of the healthbar to the position of the game character (or whatever), you want it to follow?
The problem with the above code is that you can’t add a value of 10 to a 3D position. It would probably have to be a Vector3 or something.
Hope it helps. Good luck 
The thing is I want the health bar as part of the GUI rather than an actual in game object. So what I need is the position of the gameObject in screen coordinates. I.e just x and y.
Thanks for trying to help 
Rollo357.
Oh, im sorry I misread you then. I thought you wanted them ingame, like the healthbars of World of Warcraft or similar…
Im not quite sure about the 3D-2D coord conversion in Unity, but im pretty sure I saw something on the subjct in the online documentation. Sorry I cant get anymore specific than that
Thanks for pointing me in the right direction Aegis, but it was actually,
WorldToScreenPoint(transform.position)
that I needed. Now I have it working pretty well, the only thing is the Y value of the health bar is pretty much in the middle of the character.
I want to have the health bar above his head, and it’s not as simple as just adding 5 or 10 or whatever, because as the character gets further away from the camera 5 (or 10) makes a bigger and bigger difference.
So I worked out that if the camera is 20 units away from the character I need to add 98 to the calculated y value, and if the camera is 58 units away I need to add 46.
Can someone see how I can use those numbers to calculate a number to add to my Y value for my health bar? I’m pretty sure it’s simple I’m just being a moron. 
Thanks,
Chris
You could theoretically just make it a 3D object over it that scales based on its value, too. The 3D object would naturally be positioned properly and grow and shrink based on the distance from the camera.