- Home /
how the player control on volume in the game?
hello! at my main menu i want to ask how do i can make in the main menu a Gauge that will give to the gamers an option to contol the volume that gonna be on the game?
Answer by Statement · Dec 10, 2010 at 05:49 PM
You can use a horizontal or vertical slider to allow the player to chose sound level.
You change sound level globally by changing the AudioListener.volume, or indivudually for each sound or group by changing the AudioSource.volume. Note that those are two different properties, they just look alike.
I have a problem in adjusting the volume of my Audio Listener.When I try to drag the thumb of the slider, the volume of the background music is still the same which was set as 10. Is there anything that I should modify in my script? Here is the script:
// Draws a horizontal slider control that goes from 0 to 10. var hSliderValue : float = 2.0; static var volume : float;
function OnGUI () { hSliderValue = GUI.HorizontalSlider (Rect (50, 25, 100, 30), hSliderValue, 0.0, 10.0); GUI.Box(Rect(0,0,200,50),"Volume"); AudioListener.volume = 5 * hSliderValue; }
coco your script works fine for me I set the hslider value in the inspector to 10 and changed AudioListener.volume = 5 hSliderValue; to AudioListener.volume = 0.1 hSliderValue; I have a character who gets in and out of cars at which point the audio listener changes and it still works.Hope this helps,I'm not very good at scripting so I found this out by experimenting so If you still have problems I don't know what it could be.
Your answer
Follow this Question
Related Questions
Close GUI help. 1 Answer
Main Menu scrpit not working 1 Answer
how to make a main menu? 3 Answers
How To Make A Pause Menu? 1 Answer
how to make a main menu? 1 Answer