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 Aeneas_Ferguson · Aug 08, 2021 at 03:33 AM · uisliderhealthbar

How to show the change in slider value

I have a boss in my game with a slider as a health bar, and I what I want to have happen is when the player hits the boss, it shows the amount of damage (how much the slider value decreased) that has been done. For example, if the boss is at 45% health and the player hits him and does 15% damage, I want to show that value next to the boss health bar.

Comment
Add comment · Show 6
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 rage_co · Aug 08, 2021 at 04:33 AM 0
Share

You can create 2 health slider images (one over another)....when the boss gets hit, immediately set the image on top (which is visible at all times)...to the new health value, but use a coroutine to wait for some time (maybe 1 second) before you lerp the second image to the real health value, this will create a really nice effect, but make sure to set it up so that if the boss is hurt again, both the top image, and the hidden damage indicator, are first immediately set to the current (before damage) value of health...and then the top layer is set immediately to the new damage value to create a convincing effect...if you need any clarification or help, tell me...hope this atleast points you in the right direction

avatar image Aeneas_Ferguson rage_co · Aug 08, 2021 at 04:42 AM 0
Share

@rage_co Thanks for the answer, this seems really cool, but I'm not sure how to do it. I was more thinking of showing the amount of damage done using a float that is displayed next to the healthbar, like in Bloodborne or Dark Souls.

avatar image rage_co Aeneas_Ferguson · Aug 08, 2021 at 04:46 AM 0
Share

hmm, can you share the damage taking bit of your code?

Show more comments

1 Reply

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

Answer by rage_co · Aug 08, 2021 at 05:30 AM

Well in that case it is really easy....First you need to create a text gameobject and place it close to the healthbar, (where you want to display the damage) make sure it's scaled properly to allow for multiple digits (you can customise it for color or anything, or even use Textmeshpro which is a free unity asset to create more customisable text)...these steps are very subjective and you will have to setup this yourself....

after that add this directive at the top of your script..

 //if you are using the built in text, which i suppose you already have since you are using sliders with images
 using UnityEngine.UI;
 
 //if you are using TextMeshPro
 using TMPro;

then create a reference to your text or textmeshpro in the script

 //default
 public Text deltaDamage;
 
 //TextMeshPro
 public TextMeshPro deltaDamage;

after that you can simply do this...

 if(other.collider.tag == "Sword" )
      {
          if (PlayerAnimator.GetCurrentAnimatorStateInfo(0).IsName("hit"))
          {
              hit += 1;
              float damage = 7f;
              swordImpact.Play();
              anim.SetBool("damage", true);
              slider.value -= damage;
              deltaDamage.text = damage.ToString();
              ParticleSystem.Emit(100);
         } 
     }

make sure to set the text to nothing in the start method...

 void Start()
 {
   deltaDamage.text = "";
 }

and it's that simple.... hope this helps

Comment
Add comment · Show 2 · 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 Aeneas_Ferguson · Aug 09, 2021 at 12:31 AM 0
Share

@rage_co Thanks! I didn't know it was that simple!

avatar image rage_co Aeneas_Ferguson · Aug 09, 2021 at 02:20 AM 0
Share

No problemo, all the best with the game

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

217 People are following this question.

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

Related Questions

How to connect multiple sliders for health bar? 3 Answers

Script updates prefab but not instantiated clone of prefab 0 Answers

UI Slider value gets stucked in loop and Doesn't increase further 0 Answers

Triple Slider control - UI slider value control 1 Answer

Can't drag slider onto inspector 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