- Home /
Using Pause and sound on/off in Toggle
I have this code and would like to add an audio on/off and pause to it but i keep getting errors, please advice.
@script ExecuteInEditMode()
private var toggleState1 : boolean = false;
private var toggleState2 : boolean = false;
function OnGUI() {
toggleState1 = GUI.Toggle(Rect((Screen.width - 800)/2, 20, 150, 20), toggleState1, "Sound on/off");
toggleState2 = GUI.Toggle(Rect((Screen.width - 800)/2, 40, 150, 20), toggleState2, "Pause");
}
Answer by aldonaletto · Jan 16, 2012 at 02:26 AM
Use AudioListener.pause to pause all sounds in your game - audio.mute only mutes the AudioSource of the script owner object.
@script ExecuteInEditMode()
private var toggleState1 : boolean = false; private var toggleState2 : boolean = false;
function OnGUI() { toggleState1 = GUI.Toggle(Rect((Screen.width - 800)/2, 20, 150, 20), toggleState1, "Sound on/off"); AudioListener.pause = toggleState1; toggleState2 = GUI.Toggle(Rect((Screen.width - 800)/2, 40, 150, 20), toggleState2, "Pause"); Time.timeScale = toggleState2? 0 : 1; }
Answer by dorpeleg · Jan 15, 2012 at 07:28 PM
this is my pause button code
if(Input.GetButtonUp("Pause")){
if(Time.timeScale > 0)
Time.timeScale = 0;
else
Time.timeScale = 1;
}
and you can use audio.mute = true/false to toggle music
Your answer
Follow this Question
Related Questions
Audio Toggle Background Music (With Trigger ) 2 Answers
Listen to audio when stepping frame by frame in editor 1 Answer
AudioSource glitching when resuming from suspend on iOS 0 Answers
How to toggle between paused mode and running mode? 1 Answer
Audio Toggle,Toggle Audio After Game Object Is Enabled 0 Answers