Author Topic: How to Control AudioListener.Volume With NGUI Sliders  (Read 9418 times)

Alayna

  • Guest
How to Control AudioListener.Volume With NGUI Sliders
« on: May 01, 2012, 05:21:32 PM »
I have been trying for a while to figure out what script I should attach to the NGUI Slider in order to make it control the overall volume. I have already looked for as many answers as I can on Unity Answers and the NGUI forms here and have so far had no luck. I would very much appreciate it if someone could share with me a script to perform this function, and maybe explain how it works. Thanks in advance!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to Control AudioListener.Volume With NGUI Sliders
« Reply #1 on: May 01, 2012, 08:22:43 PM »
Assuming your audio source and listener is on the main camera (as is the case with all sounds coming from the UI), you could simply attach this script to your slider:

  1. using UnityEngine;
  2.  
  3. public class ControlVolume : MonoBehaviour
  4. {
  5.         void OnSliderChange (float volume)
  6.         {
  7.                 Camera.main.audio.volume = volume;
  8.         }
  9. }

Echo

  • Guest
Re: How to Control AudioListener.Volume With NGUI Sliders
« Reply #2 on: November 29, 2012, 09:41:07 PM »
That isn't working, did an NGUI update change this?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to Control AudioListener.Volume With NGUI Sliders
« Reply #3 on: November 30, 2012, 05:49:46 AM »
Old post. Yes, modify NGUITools.soundVolume.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to Control AudioListener.Volume With NGUI Sliders
« Reply #4 on: November 30, 2012, 05:51:04 AM »
Oh yeah, and there is UISoundVolume as well.