Health Bar Help

Hello again guys, Ive been having a few problems with a health bar tutorial I adapted to my characters health I found on youtube, and I was wondering if anybody can give me some pointers.

var hp : float;
var maxhp : float;
var healthbarwidth : int;
var PlayerHealth = 500;
var myhealthbar : GameObject;
var myhb : GameObject;

function Start(){
	healthbarwidth = 20;
	myhb = Instantiate(myhealthbar, transform.position, transform.rotation);  
}
function Update(){
	myhb.transform.position=camera.main.WorldToViewportPoint (transform.position);
	myhb. transform.position.x-=.05;
	myhb. transform.position.y-=.05;
	myhb. transform.localScale=Vector3.zero;
	var healthpercent : float = hp/maxhp; 
	//if (healthpercent<0){healthpercent = 0}
	//if (healthpercent>100){healthpercent = 100}
	healthbarwidth = healthpercent * 20;
	myhb.guiTexture.pixelInset=rect(10,10,healthbarwidth,5);
}function KillPlayer () {
Application.LoadLevel (0);
} 

function OnCollisionEnter (hit : Collision) 

{ 

	if(hit.gameObject.tag == "Seagull1")

	{

	hp -= 50;

	if (hp < 0){    

		KillPlayer();
		
	}

    }
}

the commented out parts give me an error telling me to add a semicolon, I don’t know where but, as adding them only adds more errors. And when I comment it out, I get an error saying “Unknown identifier: ‘rect’.”
Any tips would be appreciated.

I’m not extremely familiar with JS, but I am fairly certain that “rect” needs to be “Rect”. Methods are case-sensitive.

Hello there!

Like msleeper said it has to be Rect. Furthermore the reason Unity asks for semicolons is because you haven’t closed the lines within the if-statements with semicolons.

if (healthpercent<0) { healthpercent = 0; }
if (healthpercent>100) { healthpercent = 100; }

Like so.

Thanks for the help, the script is compiling without errors now, but I don’t see a healthbar (with a gui healthbar texture attatched) Should I attatch it to my camera or my Player (neither of them work anyway) can you think of a reason as to why it won’t work?

for me I use a small cube attached to whatever needs a health bar, then scale the size of the cube using health / maxHealth. GUI gives me a headache so I like the cube approach… that and it took a whole 30 seconds to get it up and running.

at this time, Im really just trying to make this work, thanks for the advice though, Ill keep it in mind.