Simple 3D Healthbar

I have searched the forums, and have yet to find a way to do a simple 3D healthbar floating over an object (in my case a unit)
so I have decided to just try and figure it out. I made a cube, set its starting colour, and made it always look at the camera. i made it change colours when the health variable reaches certain points.

I have no idea how to change the cubes scale(along the x axis) based on the value of my health variable. Can someone show me a really simple way to do this (I’m deicent at JavaScript, but far from good).
Any help would be greatly appreciated,
thanks!
-Chris

Have you tried using a GUI?

var maxhealth = 100;
var curhealth = 100;

function OnGUI ()
     {
     GUI.Box(Rect(10, 10, Screen.width / 2 / (curhealth / maxhealth), 20), curhealth + "/" + max health)
     }

Search for and download the community RTS project, “Generals.” It should have an example of what you’re looking for. Iirc, there is also a mega-thread on the health indicators alone, from a couple years ago.

Okay, so using localScale i can change the scale of the healthbar, but how can I make it relative the the value of the health variable?

transform.localScale.x =curhealth/maxhealth;

thanks for your help, this works perfectly!