Trouble with floating healthbars

Hi guys, this is my first post on the forum, and i like to start off with a problem i’m having.

I’m trying to make floating healthbars for some units.
the problem is that i can’t seem to place the healthbars over the unit, i’ve searched and looked all over and nothing results in a solution for me.

I appreciate any help! =)

This is what i have so far:

Camera myCamera;
    void Start () {
        myCamera = Camera.mainCamera;
	}

	void Update () {
        transform.position = myCamera.WorldToViewportPoint(transform.position + Vector3.up * (15 / 10));
	}

What are you using for the health bar? is it a GUI item or geometry? If you’re using geometry, like a plane or something, you can just make it a child of the enemy/player and then you won’t have to worry about positioning it. It will always stay at the same position in relation to the character.

i am using a GUITexture for the healthbars, i’ve tried using a plane, but didn’t figure out how to reduce its size when the unit takes damage.

reducing the size of a plane is really simple, it could be done like this:

var healthPlane : Transform;
var healthBarLenght : int;

function Update() {
   healthPlane.scale.x = healthBarLenght;
}

Ok, this method is working, but it doesn’t look good.

Thank you anyway!