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 imnickb · May 09, 2012 at 02:19 PM · audiosliderfadelinearexponential

Adjust audio volume using an exponential curve?

I've made a slider that controls audio volume in my scene. It works fine, except that the linear fade out of the audio does not sound very good. Is there a way in script to change the way audio fades to an exponential one? Here is what I have so far:

 var hSliderValue : float = 0.0;
 var hthumbStyle : GUIStyle;
 var hsliderStyle : GUIStyle;
 
 function Awake(){
     hSliderValue = 10.0;
 }
 
 function Update(){
     AudioListener.volume = hSliderValue/10.0;
     fl_time_left = hSliderValue;
 }
 
 function OnGUI () {
     GUILayout.BeginArea (Rect (Screen.width/20+9, Screen.height/2+254, 376.5, 31.5));
     hSliderValue = GUILayout.HorizontalSlider (hSliderValue, 0.0, 10.0,hsliderStyle,hthumbStyle);
     GUILayout.EndArea ();
 }
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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Graham-Dunnett · May 09, 2012 at 02:52 PM

Why not make the slider vary from 0 to 100. When the slider moves, convert the slider value into an integer. The use this integer to index into an array of 100 values. Use the value you get from the array as the AudioListener volume. Now the problem becomes populating the array with the volumes that you want. I guess I'd fiddle with the Mathf.Exp function with x in the range 0 to 1, and scale the return value into the range 0..1. (Exp(1) is 2.71828f). I don't know if this curve is what you want for audio volume, so you'll need to experiment. You can hardcode the values in this array in Awake().

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 electricsheepAmsterdam · Feb 02, 2018 at 09:06 AM

I know this is an oldy but just landed here with the same question. My solution was simple enough, like you said just make it exponential. I have a volume var scaled 0-100. I found raising it to 1.75 was a good balance giving good response along the scale but you can easily tweak that.

AudioListener.volume = Mathf.Pow (myVolume / 100f, 1.75f);

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

7 People are following this question.

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

Related Questions

Linear volume control of AudioMixer groups 0 Answers

Why do AudioMixerSnapshots not crossfade properly when transitioning? 0 Answers

Fading out before load script not functioning correctly? 2 Answers

The volume does not reduce when master volume is lowered using volume slider 3 Answers

Activate sound without Pro filters 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