Search Unity

(Solved!) Javascript-Turning Down The Volume Of Multiple Audio

Discussion in 'Scripting' started by Nikola310, Nov 30, 2015.

  1. Nikola310

    Nikola310

    Joined:
    Oct 24, 2015
    Posts:
    35
    Greetings,everyone!

    I've made a Main Menu,that has two buttons and a slider.The buttons are "Play Game" and "Quit",and they're working.
    The slider is about audio.I want to be able to control ALL audio with that one slider.Currently I have 3 audio in total in my game:The music,and two small sounds.
    The only audio that I can control for now is the music.
    I think that I should create an audio array,and in the inspector put in the 3 audio but I don't know how to do that.
    Here is my "MusicPlayer" script:

    Code (JavaScript):
    1. #pragma strict
    2.  
    3. var music : AudioSource;
    4.  
    5. function QuitGame ()
    6. {
    7.     Debug.Log ("Game is exiting..");
    8.     Application.Quit ();
    9. }
    10.  
    11. function StartGame (level : String)
    12. {
    13.      Application.LoadLevel (level);
    14. }
    15.  
    16. function SetGameVolume (vol : float)
    17. {
    18.     music.volume = vol;
    19. }
    20.  
    Thanks in advance!
     
  2. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    You can control all of the audio by manipulating the audio listener volume.
     
  3. Nikola310

    Nikola310

    Joined:
    Oct 24, 2015
    Posts:
    35
    Thank you,it works :)