2
\$\begingroup\$

I wanna pause the Audio if I press the Pause Button also, I need help..

Pause Script:

#pragma strict

var pausemenu: GameObject;

public function pause() 
{
    pausemenu.SetActive(true);
    Time.timeScale = 0;

}

public function Resume () 
{
    pausemenu.SetActive(false);
    Time.timeScale = 1;
}

public function Restart ()
{
    Application.LoadLevel("IntroScene");
    Time.timeScale = 1;
}

public function MainMenu ()
{
    Application.LoadLevel("string");
}

public function Quit ()
{
    Application.Quit();
}
\$\endgroup\$
  • \$\begingroup\$ Please take some time to read our help center; your last several questions have been some combination of unclear, asking about basic programming process, or asking for help debugging a vague problem in your code. These sorts of questions aren't a good fit for this site and are better asked on someplace like GDNet or edited to be more focused and clear. \$\endgroup\$ – user1430 Apr 3 '16 at 15:50
  • \$\begingroup\$ Thanks for the tip, but i just wanted to pause the AudioSource if I press the Pause button, what information do I have to write in here too ? \$\endgroup\$ – NewmakerCompany Apr 3 '16 at 15:58
  • \$\begingroup\$ @JoshPetrie I think this question is perfectly clear. \$\endgroup\$ – Philipp Apr 3 '16 at 15:58
  • 1
    \$\begingroup\$ @NewmakerCompany Most of your questions (recently) seem to be of the form "I want to do <vague thing>, here's <some code>." This is problematic in general because generally there are many ways to interpret the problem you're having getting from <some code> to accomplishing <vague thing>. The more details you provide about the context surrounding your problem, what you tried, and what specific issues you are having, the better. \$\endgroup\$ – user1430 Apr 3 '16 at 16:04
  • 2
    \$\begingroup\$ @NewmakerCompany For example, is this question, is your problem that you don't know how to tell the audio system to stop processing audio? Is your problem that you don't know how to hook up a button's event handlers to the "pause/Resume" functions you wrote? Is your problem that you don't know how to call these pause/resume functions in response to a key press? Is your problem that you have a compiler or runtime error when you try? Is your problem that you get everything written so it appears to work and breakpoints hit but the audio still plays? \$\endgroup\$ – user1430 Apr 3 '16 at 16:05
3
\$\begingroup\$

Call AudioListener.pause = true in function pause and then AudioListener.pause = false in function Resume. While the audio listener is paused, the whole sound system will be essentially frozen. When you set the paused state to false again, the audio system will resume playing as if nothing had happened.

If you have some sounds which you still want to play during pause (audio feedback from your pause menu, for example), set ignoreListenerPause = true on the AudioSources of these sounds.

| improve this answer | |
\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.