Search Unity

Change sound volume with slider

Discussion in 'Scripting' started by michael bricout, Oct 25, 2011.

  1. michael bricout

    michael bricout

    Joined:
    Aug 26, 2010
    Posts:
    59
    Hi,

    I would like to change the volume of a specifique sound in my scene with a horizontal slider.

    I'm working in C#.

    Here the code that I have :

    Code (csharp):
    1.  
    2.  
    3. GUI.Box (new Rect(10,10,100,150), "Volume");  
    4.  
    5. GUI.Label(new Rect(10,10,100,20),"Son N°1");
    6.  
    7. hSliderValue1 = GUI.HorizontalSlider(new Rect(ox,oy+60, l, 20), hSliderValue1, 0.0F, 10.0F);
    8.  
    9. AudioListener.volume = hSliderValue1/10;
    In my scene I have several sounds and I would like to change their setting with different slider.

    Example :

    Souns 1 change with slider 1
    Sound 2 change with slider 2

    ...

    In my code how can I add the sound that will be modify by my slider ?

    Thanks for yoru help ! ;)
     
  2. giyomu

    giyomu

    Joined:
    Oct 6, 2008
    Posts:
    1,094
    i replied for you on UnityFrance already , use audioSource, and change audio listener will change volume for all source in your scene, this is no use here for your case , just get an audio source per slider you need and set clips on them.

    in other term work with AudioSource ;)
     
unityunity