Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: neccta on December 13, 2014, 05:39:03 AM

Title: Volume Slider
Post by: neccta on December 13, 2014, 05:39:03 AM
I setup 3 volume sliders that work just fine. However if you were to move the volume slider for 'music' it would still effect the volume for 'sound'. I have two child gameobjects under MainCamera one for music the other sound, each one with a audio source.

  1.         void Start () {
  2.         UISlider slider = GetComponent<UISlider>();
  3.         EventDelegate.Add(slider.onChange, masterVol);
  4.         EventDelegate.Add(slider.onChange, soundVol);
  5.         EventDelegate.Add(slider.onChange, musicVol);
  6.         }
  7.        
  8.         // Update is called once per frame
  9.         void Update () {
  10.        
  11.         }
  12.     void masterVol()
  13.     {
  14.         GameObject.Find("Sound").audio.volume = +UISlider.current.value;
  15.         GameObject.Find("Music").audio.volume = +UISlider.current.value;
  16.         //Debug.Log("Sound volume: " + UISlider.current.value);
  17.     }
  18.     void soundVol()
  19.     {
  20.         GameObject.Find("Sound").audio.volume = +UISlider.current.value;
  21.     }
  22.     void musicVol()
  23.     {
  24.         GameObject.Find("Music").audio.volume = +UISlider.current.value;
  25.     }
Title: Re: Volume Slider
Post by: ArenMook on December 15, 2014, 12:39:30 PM
Of course it does. You are registering all 3 listeners to the same slider in your Start() function.