percentage of a variable,

Hi,

I’m looking at a simple health bar where the gui width = player health, and then decreases, and I like it, it’s not too bad. But say my players health reaches into the thousands… my box will eventually be off screen.

I need a way to use a percentage of the player health to be my health bar.
If possible, (as the image i’m using is 200x20) i’d like the health bar to width set at 200, so the player health can be what ever it wants…

this is all i’ve got so far -
thanks so much for any help!

	void OnGUI(){

		GUI.DrawTexture(new Rect(10,10,currentHealth ,bgHeight), bg);
		GUI.DrawTexture(new Rect(10,10,frameWidth,frameHeight), frame);

		GUI.Label(new Rect(frameWidth / 2.5f, 10 , frameWidth,frameHeight), currentHealth.ToString() + " / " + maxHealth.ToString());

	}

	void Update(){

		if(Input.GetKeyDown(KeyCode.Return)){

			currentHealth -= 10;

		}

	}

This should work!

healthbarWidth = (currentHealth / maxHealth) * healthbarOriginalWidth;

I hope the variable names are representative enough!

Hope this helps!

I had this set up and working for several of the games I worked on in school. YAY RPGS!

you would want a set width for the bar let’s say 50.

So, bgWidth = 50 * (maxHealth/currentHealth).