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
0
Question by Yetter · Feb 09, 2016 at 08:18 PM · uislider

Multiple Sliders act as one.

I've been struggling with this for several hours now. Making a ship combat sci fi game and I want to implement a system where the player can transfer power between weapons, engines and shields. I've set this up with 3 sliders, each represents one system. if I were to increase shield power by 10% both weapons and engine power should drop by 5%.

I've been trying to accomplish this with the onValueChanged function. I calculate the amount that has been changed and whether it is positive or negative by storing the startvalue and subtracting the new value. Then onValueChanged calls a function that subtracts the changedvalues to the other systems but its not working properly and its becoming really messy with too many nested if statements. i think the problem is how unity is dealing with the rounding as the value is only every changing by one number at a time and unity is subtracting 0.5 from the other system and rounding the results but quite frankly the method I am using is not efficient.

Has anyone tried to build a similar system and has any advice on how I should approach this problem?

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 Dozy- · May 11, 2019 at 09:07 AM 0
Share

Sorry to bother, but I'm trying to do something similar. Were you able to find a solution?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by hexagonius · Feb 09, 2016 at 09:31 PM

I think you don't need to calculate the difference from the slider. OnValueChanged you know the current value of the slider (.6?) and the total of 100% (1) AND that there is two more sliders. so

1f - .6f = .4f

.4f / 2 (sliders) = .2f

that's the new value for both of the others. do this calculation on any if the sliders change and apply the result to the other two. since this is always starting from 1, there is no loss in precision

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 Yetter · Feb 09, 2016 at 10:20 PM 0
Share

Brilliant! Thank you, I don't know why I've been having so much trouble wrapping my head around this. I'm at work now when I get home I'll play with this approach but it certainly seems like it will work. Thanks for the response ! :)

avatar image Yetter · Feb 10, 2016 at 04:50 PM 0
Share

So, I ran into a couple issues with this method, the biggest issue is it doesn't allow me to have the sliders set at 3 separate values. i.e if I were to put the Shields at 70%, the weapons and engines would automatically put to 15% each. I couldn't set shields to 70, weapons to 20 and engines to 10. The other issue is if I put the onValueChanged attached to each of these sliders it essentially creates an infinite loop as the it is constantly evaluating all three slider, but I figure I can fix this problem by using a function like onDrag ins$$anonymous$$d of onValueChanged.

Any advice?

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

52 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

Related Questions

Slider representing player's movement 1 Answer

How to create a difficulty slider/setting for a unity game in a setting scene 1 Answer

Adjusting Audio Volume via UI Slider 0 Answers

Held UI button C# 0 Answers

Slider Component Problem (Health Bar) 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