How to bind player health to an image with Unityscript (Unity 4.6)?

How would I go about binding a variable from my player script to an image script?
Id like to take the health of my player, and set the fill amount of the image to Health/maxHealth.
I dont know how to go about using both variables in the script for the image. The only tutorials on this were pre-4.6 so they aren’t of much use due to the new UI functions.
Can anyone help?

I’m confused with your question, because you are talking about the image script and fill, which the fill is part of a slider. Either way, you must derive from Unity’s UI:

using UnityEngine.UI;

If you’re talking about using a slider, you could use:

C#

GetComponent<Slider>().value = health;

JS

GetComponent(Slider).value = health;

If you’re using an image, I assume you’re talking about the alpha. You could use something like this:

C#

GetComponent<Image>().Color = new Color([r], [g], **, health / 255);**

JS
GetComponent(Image).Color.a = health / 255;
Keep in mind [r], [g], should be filled in with the color you want.
Of course with the slider, your max health should be the same as the max value on the slider. You could also use health / maxHealth * maxSlider to get the exact value if the slider or max health change at any point. For example, if you current health is 85/100, and the max slider is set to 1, 85/1001 = 0.85, which is the correct location on the slider. If your max slider was 88 (for whatever reason), 85/10088 = 74.8, which is also the correct location on the slider.