- Home /
Slider problems + how do I make a brightness slider
So, my game has an options menu, play menu and the game. Each of those is a separate scene so options is one scene, main menu is one scene, easy mode is one scene etc.
In my options menu I have an an empty game object with a script 'Options' that contains an audio slider:
var hSliderValue : float = 1.00;
function OnGUI () {
hSliderValue = GUI.HorizontalSlider (Rect (Screen.width/2-622/2, 165, 130, 60), hSliderValue, 0.0, 1.0);
AudioListener.volume = hSliderValue;
}
The slider works fine and changes the volume in game, however every time I return to options menu, the slider returns to it's max (1). How do I make it so that it keeps the value that I chose?
Also, how would I make a brightness slider? I googled it but nothing has worked for me as I'm rather new to Unity and don't understand a lot of things.
Answer by DiegoSLTS · Mar 22, 2015 at 12:31 PM
About the slider restarting, scenes don't remember their state, they're always loaded with the values you set in the editor.
If you want your slider to display your current audio volume then set the slider to that value when the scene is loaded, you can do that in an Awake or a Start method in some script before the GUI is drawn.
About the brightness, I googled a little and it looks really complex, you need post processing shaders to make it right. A simpler solution/hack would be to add a black rectangle over the whole screen with zero alpha, and change the alpha from 0 to 1 when you want lower brightness. Or a white rectangle with zero alpha, and change it from 0 to 1 when you want higher brightness.
Answer by 03gramat · Aug 17, 2015 at 12:59 PM
I realise this question is old, but this tutorial works with the updated menus (Unity4+5) incase anyone else comes across this question and can't get it working.
Your answer
Follow this Question
Related Questions
Table Counting 2 Answers
Volume Slider 0 Answers
How can I load post processing profile throught a script ? 0 Answers
Setting Scroll View Width GUILayout 1 Answer
Can someone help me fix my Javascript for Flickering Light? 6 Answers