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 /
avatar image
0
Question by Tabu · Mar 27, 2018 at 05:18 PM · uimovementslidervaluevalues

Triple Slider control - UI slider value control

I am in a bit of a pickle, and I am trying to solve it in the best way possible. I am trying to achieve that the 3 sliders are all summing up to 1 in total, and if one slider is shifted, then the other ones will adjust proportionally. I have the following script: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;

 public class TripleSliderAdjustment : MonoBehaviour {
     private Slider primaryslider;
     public Slider sliderB;
     public Slider sliderC;
 
     private void Start()
     {
         primaryslider = GetComponent<Slider>();
     }
 
     public void UpdateSliders()
     {
         float sliderCValue = ((1 - primaryslider.value) / (sliderB.value + sliderC.value)) * sliderC.value;
         float sliderBValue = ((1 - primaryslider.value) / (sliderB.value + sliderC.value)) * sliderB.value;
 
         sliderC.value = sliderCValue;
         sliderB.value = sliderBValue;
     }
 }

This script is attached to each sliders, and SliderB and SliderC is both manually placed. However, the problem arise when I move one slider, then the other sliders are also updated, and there is somewhat of a performance issue, as all 3 are then updated, and all 3 will then attempt to update.. and there is a "semi infinite loop" going on (it will eventually stop.. but will go on for a while) Does anyone have a suggestion on how this could be solved - as I am going completely blind on this topic :) If I find the answer myself, I will post it here.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by hexagonius · Mar 27, 2018 at 05:27 PM

each slider should have an value changed event. if you register the update sliders method to all of them you just need to iterate then once, skip the one which already has the correct value and recalculate the others.

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 Tabu · Mar 28, 2018 at 05:10 AM 0
Share

I am not sure I completely understand what you are saying here - but you are telling me that I should only focus on the one slider I am moving, and then update the other two? So, this is the problem in a nutshell, I do not know which one have the correct value (or in fact, all 3 of them have the correct value at all time) So what I need to know is - which one slider am I moving? Is there any neat trick to seeing which one is manually changed and which ones are changed through scripts? If I update Slider A - then Slider B and Slider C will both be updated - each of them will now update the two others ones -- and so on :) Sliders

sliders.png (47.3 kB)
avatar image hexagonius · Mar 29, 2018 at 05:47 AM 0
Share

the value changed event should also return the changed value. comparing that and you'll know which one it was that changed.
Of course, since all sliders would call the same method you'd need be remember the ones you're adjusting and skip their callback during your updating loop.

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

166 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

Related Questions

Better way of making a 4.6UI slider to return even values only 1 Answer

How do I move my train with a slider, and not W & S 1 Answer

Getting the Value of a slider with 4.6 UI 2 Answers

How to Make a Vertical-Scroll Number Input Field, i.e. < > Value Amount 0 Answers

Get UI Slider Value 3 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