- Home /
Music Slider hookup?
I'm trying to make an options menu in which there is an audio slider that alters the volume level of the main menu. I've looked this up and it looks fool proof, I'm embarrassed that I can't get this but it must be something really simple. This is effectively how its rigged up right now, I'm using Javascript.
#pragma strict
var pauseText : String;
var paused : boolean;
var optioned : boolean;
var volume : float;
var musicSlider : float;
function Start () {
pauseText = "Pause";
paused = false;
optioned = false;
volume = 100.0f;
musicSlider = 100.0f;
}
function Update () {
audio.volume = musicSlider;
if (paused == true){
Time.timeScale = 0;
} else {
Time.timeScale = 1;
}
}
function OnGUI () {
if (GUI.Button (Rect (240,420, 70, 40), pauseText)) {
paused = true;
}
//DEALS WITH THE MAIN PAUSE MENU
if (paused == true){
(GUI.Box (Rect (50,50, (Screen.width - 50), (Screen.height - 50)), (" ")));
//This is the ONGUI code for the Options menu
if (optioned == true){
musicSlider = GUI.HorizontalSlider (Rect (((Screen.width * 0.5) - 50), ((Screen.height * 0.5) + 20), 100, 40), musicSlider, 1.0, 10.0);
if (GUI.Button (Rect (((Screen.width * 0.5) - 35),((Screen.height *0.5) - 100), 70, 40), "Menu")) {
Application.LoadLevel("StartScreen");
}
if (GUI.Button (Rect (((Screen.width * 0.5) - 35),((Screen.height *0.5) - 50), 70, 40), "Back")) {
optioned = false;
}
//This is the ONGUI code for the Main menu
} else {
if (GUI.Button (Rect (((Screen.width * 0.5) - 35),((Screen.height *0.5) - 100), 70, 40), "Menu")) {
Application.LoadLevel("StartScreen");
}
if (GUI.Button (Rect (((Screen.width * 0.5) - 35),((Screen.height *0.5) - 50), 70, 40), "Resume")) {
paused = false;
}
if (GUI.Button (Rect (((Screen.width * 0.5) - 35),((Screen.height *0.5)), 70, 40), "Options")) {
optioned = true;
}
}
}
}
Right now whats going on is that the audio kicks on at full blast (which is to be expected with how i set them to full in the beginning.) Hitting pause does pause the game, but moving adjusting the slider does nothing to effect the volume. In fact really everything that isn't the volume slider, and that has actually been implemented, functions as I expect it to. Do I need to call it differently in the update or ongui function?
Does it affect the musicSlider variable? Print it out to see if this one is changing.
Yes, i put a Debug.Log(musicSlider); in there and its bouncing healthily between the $$anonymous$$imum and maximum when i adjust the slider back and forth. Its just not getting applied to the actual audio for some reason....
Answer by TSI25 · Dec 12, 2013 at 08:36 PM
I figured it out!
i declare in this line
musicSlider = GUI.HorizontalSlider (Rect (((Screen.width 0.5) - 50), ((Screen.height 0.5) + 20), 100, 40), musicSlider, 1.0, 10.0);
that the music should toggle between 1.0 and 10.0. the volume can only actually be set to a value between 0.0 and 1.0 (i think... at least thats how it is in the editor.) Anyway i reset those values to 0.0 and 1.0 respectively and now it works like a charm.
Your answer
Follow this Question
Related Questions
boolean flicker 3 Answers
Pause Menu Volume 1 Answer
Alternate solution to onGUI for GUI? 4 Answers
Placing button at corner using NGUI 2 Answers