Author Topic: Volume Slider  (Read 1473 times)

neccta

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1
    • View Profile
Volume Slider
« 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.     }

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Volume Slider
« Reply #1 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.