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
1
Question by sanamdehghan · Dec 30, 2011 at 12:10 PM · muteaudio listener

Mute Button

I try to make a mute button on my HUD. So I used the code I found here: http://answers.unity3d.com/questions/15307/i-need-to-make-a-mute-button-solved.html

According to the above link, I add code below to my OnGUI script:

 if (M_Mute == false && GUI.Button (Rect(1090,0, 110, 110), PlayTex,   GUIStyle.none))

 {
       AudioListener.pause = true;

       M_Mute = true;

 }
 else if (M_Mute == true && GUI.Button (Rect(1090,0, 110, 110), PlayTex, GUIStyle.none))
 {
         audio.playOnAwake = false;

          M_Mute = false;
 } 

Well, this button works great when it is hit the first time, and it mutes the sound, but it doesn't replay the audio. I think I have to add this to somewhere else too, so it checks it continuously but I don't know where to put it. thanks for your helps in advanced.

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
2
Best Answer

Answer by aldonaletto · Dec 30, 2011 at 12:43 PM

You're confusing several things here:
1- AudioListener is the game "ears" - it hears all sounds and output them to the computer speakers. AudioListener.pause doesn't actually pauses the sound - it mutes/unmutes the game sound;
2- audio.playOnAwake is just an option to start playing the sound as soon as the object owner of this script is created - not all the game sounds, but only the sound attached to this object.

If you want to mute all sounds in your game, you can use this:

if (GUI.Button (Rect(1090,0, 110, 110), PlayTex,   GUIStyle.none))
{
      M_Mute = !M_Mute;
      AudioListener.pause = M_Mute;
}
But if you want to pause some specific sound and resume it later, you must place this code in the object owner of the AudioSource you want to stop/resume:

if (GUI.Button (Rect(1090,0, 110, 110), PlayTex,   GUIStyle.none))
{
      audio.Pause(); // toggles pause on/off
}
NOTE: The rectangle you've specified in GUI.Button has a too high X coordinate, and may not appear in many computers; if you want to align this button to the right side, set the first argument to Screen.width - buttonWidth, like this:
   if (GUI.Button(Rect(Screen.width-120, 0, 120, 80), ...)
Comment
Add comment · Show 1 · 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 sanamdehghan · Dec 30, 2011 at 01:23 PM 0
Share

I wanted to mute the audios so I used the approach you explained in 2. And thanks for your comment about the button coordinates.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Disable all sounds in game 2 Answers

Sound volume on different colisions 1 Answer

Turn off Priority on a Audio Source 1 Answer

Function that does not affect him Time.timeScale? 1 Answer

Audio Source Distance Issues 0 Answers


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