I keep getting errors on my healthbar code... help?

Here is my script:

using UnityEngine;
using System.Collections;

public class Playerhealth : MonoBehaviour {
public int Maxhealth = 100;
public int Curhealth = 100;

// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {

}

void onGUI() {
	GUI.Box(new Rect(10, 10, Screen.width / 2 / (Maxhealth / Curhealth) 20,), Curhealth + "/" + Maxhealth));
}

}

whats wrong with it?

Please format your code so it's readable, and copy the error message into your post so we can see the error message.

–

GUI.Box(new Rect(10, 10, Screen.width / 2 / (Maxhealth / Curhealth) 20,), Curhealth + "/" + Maxhealth)); the error is there, he is not finishing of the rectangle.

–

That, and you would get a division by zero at Screen.width / 2 / (Maxhealth / Curhealth) when Curhealth reaches 0.. if it is applicable to your design.

–

@Statement i don't really understand why he would divide the Maxhealth by Curhealth.

–

1 Answer

1

The error is this:

 GUI.Box(new Rect(10, 10, Screen.width / 2 / (Maxhealth / Curhealth) 20,), Curhealth + "/" + Maxhealth));

you have simply not finished the Rectangle.

GUI.Box(new Rect(10, 10, Screen.width / 2 / (Maxhealth / Curhealth), 20), Curhealth + "/" + Maxhealth));

Should fix it.