health bar script error

i made this health script in c# and i always get the same error i tcheck my code like 100 time and i cant find my error plz help me.

code:

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.with / 2 /(maxHealth / curHealth), 20), curHealth + "/" + maxHealth);
}

}

what is the error you are experiencing?

Please reformat your code... select it, and click the 1010 button

thanks for the kind words, im kinda proud of this one lol....also i googled up a bit and found that to create and save a new scriptable object at runtime will not be worth the trouble so i guess im going for the manual creation way now...also...do you know what's the download size of the unity editor without anything else....i updated unity hub today and it uninstalled the current editor for no reason...and i have limited internet....plus unity hub is totally opaque about the size of the editor so i guess i'll need to do some management and planning for this simple task

again, thanks for the support you've provided on this problem...im really grateful

1 Answer

1

Hey Beattonick,
Your code only had two problems, you were trying to declare variables in the wrong place, and you spelled width wrong.

using UnityEngine;
using System.Collections;
public class PlayerHealth : MonoBehaviour {

public int maxHealth = 100;
public int curHealth = 100;

void OnGUI() {
    GUI.Box(new Rect(10, 10, Screen.width / 2 /(maxHealth / curHealth), 20), curHealth + "/" + maxHealth);
    }
}