Can someone go over my health bar script?

this is my Health Bar script wondering if someone can go over it and PM me it with your mods so it works i keep getting a few errors over and over PLEASE help me :slight_smile:


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 );

}

)


For starters, when posting code try if you can to post them within the [ code ] tags for easier reading and formatting. As for the errors with your script, it simply states that the rect type could not be found, that is because in C# the naming is case sensitive and the correct type name would be Rect in the GUI.Box. Aside from that all functions as intended within the script.

Ohhh okay thanks :slight_smile:

Update#
Okay so i fixed it… but still getting the "not complaited or something error

[COLOR="blue"]
using UnityEngine;
using System.Collections;

public class PlayerHealth : MonoBehaviour {	
      public int maxHealth = 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);
	}
	
}[/COLOR]
[COLOR="darkgreen"]
[END CODE][/COLOR]

Why don’t you take the 10 seconds to actually write out the error?

Also, the code tags are like [ code] [ /code] (without the space)

EDIT: You never declared “curHealth” anywhere.

Quick jot off, then an answer to the error you’re encountering. It would be quite a bit more helpful to know the exact message from the compiler instead of an “…or something error” :wink: Now for your issue, there is no class member of curHealth so if you were to add a declaration to something similar to the following private int curHealth = 100;, it would compile without error. The console is an invaluable tool, it will tell you the exact compile error, and even the line that it is encountered on; which is usually enough information to solve the problem.

EDIT : Seems as though FizixMan beat me to the point while I was typing this out.

Do you really need to start multiple threads for this?

Yup, 500 of 'em. Yeeeaaaahhh threads everywhere!

thought you already had it done :slight_smile:

I did then i messed it up :slight_smile: ahah atleast im acutlly doing it your a little mapper boy so just shut up :slight_smile:

dude i have a health bar there is heaps of tutorials online… and what about you, start a game then just stop. good job at wasting time (Y)

insulting someone to be a “little mapper” will make you look even more of a noob.
i saw nothing from you till now. You just asked for freebees, you are not interessted in learning anything, you just want stuff made for you and you spam the whole forum. You don’t even managed to post with code-tags!!!

Less drama, more puppies.

haha

k guys i got it all fixed :slight_smile: inventory rocks Hahn

thanks evo for helping me after you fixed yours