- Home /
pause a audio inside game
function OnGUI() {
if(GUI.Button(Rect(100,200,100,50),"pause")) //to pause the game
{
Time.timeScale = 0;
}
if(GUI.Button(Rect(200,300,100,50),"play")) // to resume the game
{
Time.timeScale = 1;
}
}
here when i press pause button it should pause the game and when press play button it should resume the game where i stopped.here pause button is not working.
my need is when i press the pause button it should stop all current action including the audio which is playing in the game .
when i press the play button after pausing the game. it should start from where i paused the game including the audio where it stopped.
on further when ever i pause and play the game in the second scene .it should not play the old audio in the first scene.
i have went through this answer http://answers.unity3d.com/questions/21/how-do-i-pause-my-game
but not able to solve the problem.so i posted the question.
so can any body help me.
Answer by Kacer · Apr 06, 2011 at 07:53 AM
This might work, though i dont think it works on a global level :)
http://unity3d.com/support/documentation/ScriptReference/AudioSource.Pause.html
edit; this might work as well, but im not sure its what you're looking for: http://unity3d.com/support/documentation/ScriptReference/AudioListener-pause.html
this is not i am looking for i am looking a pesume and play menu
as in, do you want the audio to be paused when you press a button in the menu, or?
i got the answer for that question thanks for the help
Your answer
Follow this Question
Related Questions
Music On/Off Switch 2 Answers
How to know if Audio is Paused? 2 Answers
Audio Toggle Background Music (With Trigger ) 2 Answers
Changing Audio volume thru another code 2 Answers
Script using a Pause library causes audio to intermittently cutout. 0 Answers