Desired end result: A button in a pause menu labeled Settings or something like that. When that button is clicked, it opens to two slider bars, one controlling the background music’s volume, the other controlling the sound effect’s volume.
But for now, I’m just trying to get a slider bar to appear, and I’m not having much luck.
This is the script thus far.
using UnityEngine;
using System.Collections;
public class Menu : MonoBehaviour
{
public bool gameIsPaused = false;
public bool buttons = true;
private float hSliderValue = 0.0f;
void Update()
{
if(Input.GetKeyUp(KeyCode.P))
{
if(gameIsPaused)
{
gameIsPaused = false;
Time.timeScale = 1.0f;
audio.Play();
} else
{
gameIsPaused = true;
Time.timeScale = 0.0f;
audio.Pause();
}
}
}
void OnGUI()
{
if(gameIsPaused)
{
if(buttons)
{
if(GUI.Button(new Rect(Screen.width / 2 - 100, Screen.height / 2 - 75, 200, 50), "Resume"))
{
gameIsPaused = false;
Time.timeScale = 1.0f;
}
if(GUI.Button(new Rect(Screen.width / 2 - 100, Screen.height / 2 - -25, 200, 50), "Settings"))
{
buttons = false;
}
if(GUI.Button(new Rect(Screen.width / 2 - 100, Screen.height / 2 - -125, 200, 50), "Main Menu"))
{
Application.LoadLevel("MainMenu2");
}
}
if(buttons == false)
{
if(GUI.Button(new Rect(Screen.width / 2 - 100, Screen.height / 2 - -25, 200, 50), "Back"))
{
buttons = true;
hSliderValue = GUI.HorizontalSlider (new Rect (25, 25, 100, 30), hSliderValue, 0.0f, 10.0f);
}
}
}
}
}
With this code, I click the Settings button after pausing the game, and the Resume, Exit and Settings buttons dissappear, replaced by a Back button. But no slider. I copy and pasted the slider code from here (Unity - Manual: Controls) in case the reader wonders why the code for positioning the slider is different from the code positioning the buttons. Can anyone tell me why the slider is not appearing? And how I can fix it?