x


Health Question

Hello I need help with my health gui I have Everything I need for the Gui, I have it in the right place on the screen but its just Gui text. I was wondering if I could have it so I still keep the Gui text but have it decrease if the Player gets hit. Anything (scripts,Tutorials) would be really helpful. Thank you - ryan 123321

more ▼

asked Mar 07, 2012 at 01:27 AM

ryan123321 gravatar image

ryan123321
41 23 922 42

Do you have a health script on your player? Is there an 'HP' (or something) variable that you can query?

Mar 07, 2012 at 01:27 AM syclamoth
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Yes it is possible. Make an int variable called health and set that to how much health you want. Then make a variable that is an empty gameobject called health text or something. then set your gui text to that variable.(Make sure all of this is in the same script BTW.) Then access the GUI text's text attribute and set it to the health variable. Then whenever your character gets hit subtract damage from your health variable. Heres an example.

 var health = 100;
 var guiText = gameObject;

 function Update()
 {
     guiText.text = health + "";
 }

then make a function that subtracts damage from the health variable when the character is hit! If there are any errors or it is not what you want make sure to comment in reply!

more ▼

answered Mar 07, 2012 at 02:32 AM

DGArtistsInc gravatar image

DGArtistsInc
309 38 32 38

Yeah there's an error. Spell Update properly. Also, why not use health.ToString() instead of relying on automatic type promotion?

Mar 07, 2012 at 03:06 AM syclamoth

My bad thanks for small detail improvement

Mar 07, 2012 at 03:07 AM DGArtistsInc

thank you. I tryed making a script and it was simlar to this and it didnt work! Thank you so much.

Mar 07, 2012 at 09:59 PM ryan123321

sorry in the last comment it may have sounded like I was blaming you for the failure of the script but the only thing to blame was my lack of javascript skills. I am sorry if it came across that way and that was not the way I meant it. In other words Thank you for making a script and I tryed to create one but sadly it didnt work.

Mar 13, 2013 at 03:07 PM ryan123321
(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

By RSS:

Answers

Answers and Comments

Topics:

x4301
x1660
x621
x354
x39

asked: Mar 07, 2012 at 01:27 AM

Seen: 1117 times

Last Updated: Mar 13, 2013 at 03:07 PM