hi guys. i have a pause menu script that i want to script to control all in game volume. i want it to be controlled through a horizontal GUI slider, but i have been having problems with that. here’s the script:
using UnityEngine;
using System.Collections;
public class PauseMenu : MonoBehaviour
{
public GUISkin myskin;
private Rect windowRect;
private bool paused = false , waited = true;
private bool options;
private float hSliderValue = 0.5f;
private void Start()
{
windowRect = new Rect(Screen.width / 2 - 100 , Screen.height / 2 - 100, 200, 200);
}
private void waiting()
{
waited = true;
}
private void Update ()
{
if (waited)
if(Input.GetKey(KeyCode.P) || Input.GetKey(KeyCode.Escape))
{
if (paused)
paused = false;
else
paused = true;
waited = false;
Invoke("waiting",0.3f);
}
if(paused)
Time.timeScale = 0;
else
Time.timeScale = 1;
if(paused)
AudioListener.pause = true;
else
AudioListener.pause = false;
if(options)
AudioListener.volume = 0.10f;
else
AudioListener.volume = 0.2f;
}
private void OnGUI()
{
if (paused)
windowRect = GUI.Window(0,windowRect, windowFunc, "Game Paused");
}
private void windowFunc(int id)
{
if(GUILayout.Button("Resume"))
{
paused = false;
}
if(GUILayout.Button("Volume"))
{
options = true;
}
if(GUILayout.Button("Return to Main Menu"))
{
Application.LoadLevel (0);
}
}
}
do you have any suggestions in c#? thanks!