Working health script?

Hi I have this script that I have from another question that I asked and was wondering how to make the health bar smaller when I get hit by tagged bullets

public float maxHealth = 100.0f; // Minimum health is 0.0f (dead) public float currentHealth = 100.0f; // Players current health

public Texture2D background = null;

public Texture2D energybar = null;

void OnGUI() {

// Draw the background

GUI.DrawTexture(new Rect(32.0f, 32.0f, 128.0f, 16.0f), background);

// Draw the health/energy bar

GUI.BeginGroup(new Rect(34.0f, 34.0f, 124.0f * (currentHealth / maxHealth), 12.0f)); GUI.DrawTexture(new Rect(0.0f, 0.0f, 124.0f, 12.0f), energybar); GUI.EndGroup(); }

more ▼

asked Dec 31, 2010 at 08:41 PM

Phil 9 gravatar image

Phil 9
35 5 6 12

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

What do you mean by smaller? Do you mean that the GUI should be smaller? Try editing the last two parameters in the Rect's.

If you mean that when I get hit, I receive 10% of my life, so show only 90%. Then you just need to subtract currentHealth with the amount you lost.

more ▼

answered Jan 01, 2011 at 12:17 AM

Ejlersen gravatar image

2.2k 7 11 26

Yeah that is what I mean but I forgot o put that I have a script but It won't work but I can't post it because I'm on my iPod. So yeah I know what you mean but when I tried it, it didn't work.(i didn't have any GUI on it though)

Jan 01, 2011 at 06:36 AM Phil 9

You need to have two textures for it to work. I know it, because that script looks a lot like one I provided a few days ago :)

Jan 01, 2011 at 11:32 AM Ejlersen
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



asked: Dec 31, 2010 at 08:41 PM

Seen: 5410 times

Last Updated: Jul 16, 2011 at 10:57 AM