Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by ryan123321 · Mar 07, 2012 at 01:27 AM · fpsdamagedecreasehealth

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

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image syclamoth · Mar 07, 2012 at 01:27 AM 0
Share

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by DGArtistsInc · Mar 07, 2012 at 02:32 AM

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!

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image syclamoth · Mar 07, 2012 at 03:06 AM 0
Share

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

avatar image DGArtistsInc · Mar 07, 2012 at 03:07 AM 0
Share

$$anonymous$$y bad thanks for small detail improvement

avatar image ryan123321 · Mar 07, 2012 at 09:59 PM 0
Share

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

avatar image ryan123321 · Mar 13, 2013 at 03:07 PM 0
Share

sorry in the last comment it may have sounded like I was bla$$anonymous$$g 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.

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Health and damage reciever 1 Answer

hi I know that this script is seen often but I have an another problem with a damage and health scripts. I think it's the GetComponent part, well anyway if you could help that would be great. 2 Answers

Bullet not destroying on collision 1 Answer

Damage taking? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges