Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
This question was closed Dec 03, 2016 at 04:12 AM by HavenGaming for the following reason:

Unanswered and off topic just wanted to know how to get two sliders working together.

avatar image
0
Question by HavenGaming · Nov 29, 2016 at 06:47 AM · uisliderhealthbar

How to connect multiple sliders for health bar?

How do I connect multiple sliders to act as one in a script. In the picture below I have the sliders laid out in the pattern it should go through. Slider 1 = 100 and ends the rotation out at slider 4 = 0. I am not very good with arrays yet. Just need to know how to make the connection from 1 to 2 without both health bars going down at the same time. Do I need to do anything in the onValueChanged? Didn't have to mess with that on a single so I am not sure. Thank you !!

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 
 public class PlayerHealth : MonoBehaviour 
 {
     public int curHealth = 100;
 
     public Slider healthSlider1;
     public Slider healthSlider2;
     public Slider healthSlider3;
     public Slider healthSlider4;
 
 
     void Start()
     {
         
     }
         
     void Update()
     {
         healthSlider1.value = curHealth;
     }
 
     //UI Button to test damage
     public void TestDamage()
     {
         curHealth = curHealth - 5;
     }
 
healthbar1.png (124.7 kB)
Comment
Add comment
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

3 Replies

  • Sort: 
avatar image
1

Answer by Mehul-Rughani · Nov 29, 2016 at 12:24 PM

Hey @HavenGaming You can do it in two ways

1) you can do it manually.by enabling and disabling pieces of progress bar for example : when health decrease 25 disable last object and when it increase 25 enable last object of progress bar

2) make an image looks like a four slides and add that image as ui image in scene and set image type to fill and set fill amount according to your health

Hope you are looking for this:)

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 HavenGaming · Nov 29, 2016 at 07:48 PM 0
Share

@$$anonymous$$ehul-Rughani Could you give me an example of number one? I am not using images like the heart icons.

avatar image Mehul-Rughani HavenGaming · Nov 30, 2016 at 05:07 AM 0
Share

Reference image that you are using for progress bar

avatar image HavenGaming Mehul-Rughani · Nov 30, 2016 at 07:08 AM 0
Share

Im not using images. I'm using four ui sliders, and not sure how to reference each one

Show more comments
avatar image
1

Answer by Eepiz · Nov 30, 2016 at 07:38 AM

You could put your sliders in an array, set the min value of the first slider to 0 and the max value to 25, min value of the second slider to 25 and max value to 50 and so on. When setting a new health, iterate over all sliders and change their value to the new health. If the value is smaller than a sliders min value it will take it's min value, if it's bigger it will take it's max value.

 public Slider[] sliders;
 
 void SetHealth(int health) {
     foreach (Slider slider in sliders) {
         slider.value = health;
     }
 }

I hope this helps :)

Comment
Add comment · 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
0

Answer by Wolfie · Dec 01, 2016 at 01:01 AM

Looking at your GUI screenshot, another option to consider could be to treat it like a circular health bar. Create an image component with your square bars and a transparent background.

Image type - "filled" Fill method - "Radial360"

Then change the "fill amount" variable by code, multiplying so as to convert your percentage health or arbitrary health units into an angle.

Besides being simple to do, one reason I suggest this is that many other methods are liable to have issues at the corners or your square health bar, which while not game breaking, would still be noticable and would necessitate some trickier work-arounds. If you want to retain the dark border whilst cutting into the health bar, then simply put that part of the graphic on a layer above the bar itself.

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 HavenGaming · Dec 01, 2016 at 01:13 AM 0
Share

The rad began in an awkward cut with the image being a diamond otherwise I would have stuck with that. It Began and end on the midway of the first section. I tried the other settings but it did not look right.

avatar image Wolfie HavenGaming · Dec 01, 2016 at 01:22 AM 0
Share

I think you've lost me, can you post a screenshot? It sounds like you've just started out with a square and then rotated it to make it a diamond. The radial fill doesn't take your own rotation into account, so you could try taking your image, rotating it 45 degrees in Photoshop or whatever you use, and then trying the same thing again.

avatar image HavenGaming Wolfie · Dec 01, 2016 at 01:31 AM 0
Share

Got ya, make sure its already 45 before import

Follow this Question

Answers Answers and Comments

86 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

Related Questions

Script updates prefab but not instantiated clone of prefab 0 Answers

How to show the change in slider value 1 Answer

Dynamic slider size with the new UI 2 Answers

left end of slider fill flattening the more i move the value down 0 Answers

Why hip will move upward and downward automatically when start to drag slider at x,y and z axis? 0 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