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 Amit · Aug 27, 2010 at 10:55 PM · damagehealth

how do i make a script that calculate how much damage did i loss

hey, i have a player with 100 health points. everytime i get hit by an enemy, i lose a random number between 5-20 hp. i have made a prefab with the 3d text, created a font and made an animation to the text so it will be above the head of the player and go up and disapear. the text in that prefab represent the number of health points that i have loss. like if i lost 10 hp (health points) than it will instantiate the prefab with the text "10" on it. the problem is, the hp i lose is random and i dont know how to make it work... thanks.

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 zannghast · Dec 15, 2010 at 09:08 AM 0
Share

A straightforward answer is storing the random damage in a variable, then using that variable to update the text on your 'damage value prefab'. Similar with what Tylo suggested below. You did, however, reply to him that you somehow could not use that action plan. $$anonymous$$ay we know how you calculate that random damage and why you can't simply store it in a variable?

1 Reply

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

Answer by tylo · Aug 28, 2010 at 12:48 AM

This is pretty simple.

Your HP is stored in a variable, right?

Just update what the 3D text says when you lose HP like this:

YourText.Text = hp;

If that doesn't work, you'll need someway to change your hp number value to a string. That really depends on which language you are using, I think.

EDIT

Since you clarified that this is displaying the damage done, try looking at it this way.

I am unsure how you are causing your HP to deplete. It could be that the enemy is directly depleting your HP. Or it could be that your player receives the value of damage done, and then depletes his own HP.

In either case...what you need to do is this:

YourText.Text = damageDone;

If for some reason you can't do that, then you can do this:

int temp = hpBeforeDamage;
/* Damage is dealt */
YourText.Text = hpBeforeDamage - currentHP;
Comment
Add comment · Show 3 · 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 Amit · Aug 28, 2010 at 01:38 AM 0
Share

Sorry i probably didnt explain brifly... i need to write in the text the HP that i have lost, not the current hp, i have an hp bar for that but thanks for the answer.

avatar image tylo · Aug 28, 2010 at 04:35 AM 0
Share

Oooh, I understand now. Sort of like the -32 from getting hit, etc.

I'll edit my answer.

avatar image Amit · Aug 28, 2010 at 12:35 PM 0
Share

doesnt really help me, but i have think of something now, it ill make a var damage (And i have another var in the script called curHealth(current health)) and than ill say both of them will be the same only that the var damagae will have a delay of 1 second until it will be like the curHealth. and than in another script ill say if(damage != curHealth) for(var n=1, n<2, n++) { { Instantiate(HP); HP.text = damage - curHealth; } }

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

No one has followed this question yet.

Related Questions

Ranged damage not working 1 Answer

Health Bar fire damage 1 Answer

Universal Damage Sytem 2 Answers

Enemy Health, Player Damage 0 Answers

Help with fire damage on a health bar? 2 Answers


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