Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by userpasworld17 · Sep 24, 2020 at 08:12 PM · buttonaudiopause menuaudiolistenermainmenu

Audio problems with unity after reloading my game from the main menu

I have one problem : when I pause the game , the audio pauses too , but I created a "go back to menu" button , it goes to the main menu but when i hit start again and the game starts running , my audio is dead , i can not hear anything so if anyone knows what should I do please tell me , thanks in advance!

Here is my code : using UnityEngine; using UnityEngine.SceneManagement;

public class pausemenu : MonoBehaviour { public GameObject pauseMenu;

 public bool isPaused;

 
 void Start()
 {
     pauseMenu.SetActive(false);
 }

 // Update is called once per frame
 void Update()
 {
     if(Input.GetKeyDown(KeyCode.Escape))
     {
         if(isPaused)
         {
             ResumeGame();
         }

         else
         {
             PauseGame();
         }
     }
      
 }   
 
 
 public void PauseGame()
 {
     pauseMenu.SetActive(true);
     Time.timeScale = 0f;
     isPaused = true;
     AudioListener.pause = true;
 }
 
 public void ResumeGame()
 {
     pauseMenu.SetActive(false);
     Time.timeScale = 1f;
     isPaused = false;
     AudioListener.pause = false;
 }
  
 public void GoToMainMenu()
 {
     Time.timeScale = 1f;
     SceneManager.LoadScene("menu1");
 } 
 
 public void QuitTheGame()
 {
     Application.Quit();
 }

   

}

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image unity_MXGApNcapNfNLg · Sep 25, 2020 at 11:49 AM 0
Share

Unpause the audio listener in Goto$$anonymous$$ain$$anonymous$$enu() function as well. Like this: public void GoTo$$anonymous$$ain$$anonymous$$enu() { Time.timeScale = 1f; AudioListener.pause = false; Scene$$anonymous$$anager.LoadScene("menu1"); }

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by skagontale · Sep 25, 2020 at 12:46 PM

the reason that your audio is stopping is because you're setting the timescale to 0 meaning that you are slowing down the speed of the game to none along with the music. a work around this would be to set a public static bool in all of the things that you want to stop and then have an if statement that reads as follows over every line of code that will make an object do something: if (!bool) {enter code that you want the object to be doing} and then in your pause script trigger the bool with: name of script you want to access.name of bool you want to access = true; and then unpause by switching the true with false. as for going to the main menu i would recommend slowing down the music to a stop within a small timeframe and then restarting it when you get to the main menu

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

194 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

The same audio plays differently on a variety of buttons, how can I change this? 0 Answers

Changing two different objects renderer colour 1 Answer

How to get decibel's value of game's sound? 0 Answers

Keeping audio between all but one scene? 1 Answer

How do I only start the audio when player is at max distance 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges