Issue with Texture Change

private var totalHealth = 25;
static var health = 25;
private var healthBar : Texture2D;
var healthBar1 : Texture2D;
var healthBar2 : Texture2D;
var healthBar3 : Texture2D;
var healthBar4 : Texture2D;
var healthBar5 : Texture2D;
var healthBar6 : Texture2D;
var healthBar7 : Texture2D;
var healthBar8 : Texture2D;
var healthBar9 : Texture2D;
var healthBar10 : Texture2D;

function Start () {

var health = totalHealth;

}

function OnGUI () {

GUI.Label (Rect (Screen.width / 3, Screen.height / 1.125, 500, 500), healthBar);

}

function Update () {

if(health == totalHealth){

	healthBar = healthBar1; 

}

if(health < totalHealth - totalHealth / 10){

	healthBar = healthBar2; 

}

if(health < 1) {

	Destroy(gameObject);

}

}

The texture does not change. The health is in fact decreasing, but the texture does not change.

Any ideas?

Bump! :smile: I Would love to se how someone would fix it :slight_smile:
Could use it myself :stuck_out_tongue:

Which image does it stay on? healthBar1 or healthBar2?

Try this:

#pragma strict

    private var totalHealth:float = 25;
    private var health:float = 25;
    var healthBars : Texture[];
    private var healthBar : Texture;
     
    function Start () {
     
    health = totalHealth;
     
    }
     
    function OnGUI () {
     
    GUI.Label (Rect (Screen.width / 3, Screen.height / 1.125, 500, 500), healthBar);
     
    }
     
    function Update () {
    health -= 0.01; 
    healthBar = healthBars[parseInt(healthBars.length*health/25)];
    if(health < 1) {
     
        Destroy(gameObject);
     
    }
     
    }

Here it does.