Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by Peanut97 · Nov 18, 2013 at 12:58 AM · audiopausemusicaudio source

Different music for pause menu?

Hello,

I've been attempting to achieve this all day and I can't seem to do it. In my scene, I have a player and two audio sources. One audio source is playing the music I want for the scene (level), and the other audio source is playing the song that I want to be audible in the pause menu. When the player presses the Escape Key, a pause menu pops up. Is there any way I can get one audio source to mute, and the other audio source to unmute when the player hits the escape key? Both audio sources are attached to Empty GameObjects with 2D sounds. Thank you so much for taking the time to help me out!! Thank you!

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Tomer-Barkan · Nov 18, 2013 at 08:02 AM

One way would be to attach the following simple script to both audio sources:

     if (Input.GetKeyDown(KeyCode.Escape)) {
         audio.mute = !audio.mute;
     }

And then in the inspector, set the audio source of the scene to not muted, and the audio source of the pause menu to muted. Every time you press Escape, each audio source will switch from mute to unmute.

A more robust way to do this would be whenever you are opening the pause GUI, to mute one source and unmute the other, but you didn't share enough of your scripts for me to help you with more than the general idea.

Comment
Add comment · Show 16 · 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
avatar image Peanut97 · Nov 18, 2013 at 03:05 PM 0
Share

Thank you so much for your help! I'll give your script a go! Again, THAN$$anonymous$$ YOU!

avatar image Peanut97 · Nov 18, 2013 at 11:13 PM 0
Share

This script works for the scene audio, but when the Pause Audio source starts muted, it will not "unmute." It just stays silent. Do you have any ideas why this is?

avatar image Tomer-Barkan · Nov 18, 2013 at 11:43 PM 0
Share

$$anonymous$$ake sure you have the same code from my answer attached to the pause audio, in the Update() method. There's no reason it shouldn't work.

$$anonymous$$aking sure - there's only one audio source attached to each game object.

avatar image Peanut97 · Nov 18, 2013 at 11:58 PM 0
Share

That is correct. Only one Audio Source is added. The only problem I am having is when I start the scene with the mute box checked on the audio source, it won't unmute when I press the escape key. It just stays checked and nothing plays. Is it a glitch? I don't think so... There's gotta be something wrong here.

avatar image Tomer-Barkan · Nov 19, 2013 at 12:19 AM 0
Share

Try some debugging:

 if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Escape)) {
     audio.mute = !audio.mute;
     Debug.Log(gameObject.name + ": " + audio.mute);
 }
Show more comments

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

18 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

Related Questions

Audio slider for multiple scenes. 2 Answers

dynamic audio measuring? 0 Answers

Audio Toggle Background Music (With Trigger ) 2 Answers

Music On/Off Switch 2 Answers

how to play audio when a level is complete 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