GUI healthbar

Hi there.
I need help from anyone. Im new in unity i’m doing my healthbar. I’m using texture. Im not sure how am i gonna declare the texture cause i keep getting error unity texture 2d cannot convert to int. all i wanted was my healthbar to change its width as the healthcount is changing too.

here’s my script. hope someone can help me guys.

var maxHealth = 100;
var currHealth;
var damage :int = 10;
var myHealthbar:Texture2D ;// green
var healthbarWidth :int;
var myhp;
function Start () {
healthbarWidth = 100;
 //var myhp=Instantiate(myHealthbar, transform.position, transform.rotation);

function Update()
	  if (Input.GetKeyDown(KeyCode.F8)) 

function ApplyDamage ()

	maxHealth = maxHealth - damage ;
	healthbarWidth = maxHealth;
	healthbarWidth = myHealthbar;//maxHealth * 100;
	GUI.Box( Rect (10,10, 100,50), myHealthbar);

	if (maxHealth == 0)

function die () 
    yield WaitForSeconds(2.0);

thanks in advance:)

Haven’t worked much with the GUI yet, but I’d start by looking at updating the Size of the GUI.Box based on the amount of health left as a percentage. So something like:

GUI.Box( Rect (10,10,healthbarWidth,50), myHealthbar);

@ syclamoth actually i wanted to put the value of the healthcount or lives into the GUI healthbar that’s why i’m trying to put the healthbarwidth equals to the myhealthbar which is a texture. I don’t really how to declare the texture width that when the healthcount is decreasing the texture GUI healthbar as well.hope you get what i meant.

@IMoriaty I’m trying to separate the script from the health system to the healthbar. but i’m still having problem with the texture…

on line 24, do this :

HealthBarWidth = myHealthbar.width;

and on line 25: