- Home /
Change sound dependent on slider?
So i have a options button , and when you press you have the option to change sound volume , i have made the slider and everything but i dont know how to change all sound according to it , ad by the sounds of it its REALLY complex and i need the best help i can get . please dont be harsh as i am new to java ( i have only been doing it for about half a year )
var Msensitivity : float = 5;// dont worry about this
var Volume: float = 5;
function OnGUI () {
Msensitivity = GUI.HorizontalSlider (Rect (800, 175, 400, 25), Msensitivity, 0.0, 10);//dont worry about this
Volume = GUI.HorizontalSlider (Rect (800, 250, 400, 25), Volume, 0.0, 10);
}
I think you could save a 0.0 to 1.0 value for master volume in PlayerPrefs - Any audio sources could get the master volume and set it before playing
ok , then how do i make it so when i change the slider the volume changes aswell?
Answer by Pitomator · Dec 28, 2013 at 01:17 PM
First you are using JavaScript (or UnityScript) and not Java ;)
Try this after you Vulume = ... line:
AudioListener.volume = Volume;
Hope it helps
it works!!!!!!!!! , but one problem , i have 3 scenes in my game and it lowers the volume for one scene only
It is most likely because you store the volume in a local variable and you have the script in all your scenes. Either store it in a static variable or only have the volume adjustment script in one scene, hope it helps :) Static variables look like this:
static var volume : float = 0;
oh , how would i make it for all sound , i only did a audio source