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 /
  • Help Room /
avatar image
1
Question by Huggz · Sep 22, 2015 at 12:05 PM · uislider

Make Multiple UI Sliders Function As One

What I'm trying to do is to allow the user to divide a single resource pool into into 3 groups. I wanted to use a slider for each group indicating the percentage of the total resource pool being allocated to that group. I always want the total values of the sliders to be equal to 1 (100% resource allocation). So when one is dragged down, the other 2 go up, and when one is dragged up the other 2 go down.

I've been looking at onValueChange, but the problem I'm having is changing the slider values in the event handler results in more calls to onValueChange which ends up in a potential infinite loop of changes.

So, before I get too deep into trying to make this work myself, I'm curious if anyone has done this or has any ideas about how to go about implementing these sliders.

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 Yetter · Feb 09, 2016 at 07:31 AM 0
Share

Hate to be a pain but I am doing something very similar in my game right now and I'm wondering if you've happened to develop a decent system for this because the approach I've taken has made a big mess of code and still doesn't quite work properly.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Dave-Carlile · Sep 22, 2015 at 12:17 PM

Is the OnValueChanged event being generated even if the new value you're calculating is the same? I would hope it wouldn't be, but if it is just make sure you don't redo your calculations for the other sliders again if the value didn't actually change.

An example with 2 sliders...

  1. User sets Slider A to 20%

  2. Slider A OnValueChanged: calculate value of slider B as 80% and set value

  3. Slider B OnValueChanged: calculate value of slider A as 20% and set value

In step 3 I would hope that Slider A wouldn't get another OnValueChanged event since the value didn't actually change even though you're setting it. But if Unity still generates the event then you can just do the compare yourself and not set the property if it's the same...

  1. Slider B OnValueChanged calculate value of slider A as 20% if (slider A value != 20%) set value of Slider A to 20%

And you might want to use Mathf.Approximately for the comparison to avoid generating the event due to rounding errors.

Now, with 3 sliders, if OnValueChanged is executed immediately when you set the slider value then you'd still have problems since the 3rd slider value hasn't changed yet. You might need to keep separate copies of the values, calculate them all at once, then let the sliders pull their values from those.

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

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

35 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

Related Questions

Multiple Sliders act as one. 1 Answer

Unity UI slider seems to increment in random whole number values. Need advice please 0 Answers

Problem with Slider 1 Answer

Select ui slider to change float value? 1 Answer

Prefab UI Slider misses the fill and background items... 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