Hi.
In my searching of the image (script) for the Image type Filled. I can’t Edit it from the script since Image.fillAmount doen’t work. I only found this video:link text and This explains a C# version of what I want. Can you convert this to JS or find a code that has the same effect.
var barpoints = 100f;
function Start () {
}
function Update () {
var Rcolor = barpoints*2.5;
var Gcolor = 255-Rcolor;
var length = barpoints/100;
Image.fillAmount = barpoints;
}
The fill fillAmount method on the Image type you’re calling on the actual Image class/type and not an instance of that class. I’m bored and will just port the code over for you, but you need to learn more about UnityScript(js) or programming in general.
#pragma strict
var Bar : Image;
var max_health : float = 100f;
var cur_health : float = 0f;
function Start() {
cur_health = max_health;
InvokeRepeating("decreaseHealth", 0f, 2f);
}
function decreaseHealth() {
cur_health -= 5f;
var calc_health : float = cur_health / max_health; // 70 / 100 0.7
SetHealth(calc_health);
}
function SetHealth(var myHealth : float) {
Bar.fillAmount = myhealth;
}
Note: i did not test this and converted in notepad, enjoy.