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.