Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 mEX · Sep 30, 2011 at 11:41 AM · audiosoundpauseaudiolistenermute

Mute/Unmute not working with new sounds

I know here were several questions about mute-buttons and I could somehow use the answers here. However it's not working in a way I expected it to. When i click my mute-button all active sounds turn silent (which is good!) but alltough the AudioListener is paused, newly instantiated audioSources are hearable. When I unmute and mute again they turn silent, too, but I want a mute-button that keeps everything quiet all the time.

 private Rect _buttonRect = new Rect(10, 10, 100, 50);
 
 void OnGUI()
 {
     if(GUI.Button(_buttonRect, "Sound On/Off"))
     {
         AudioListener.pause = !AudioListener.pause;
     }
 }

Did I make a mistake, or is this a bug?

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

2 Replies

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

Answer by Grady · Sep 30, 2011 at 12:04 PM

Instead of pausing them, you could do AudioListener.volume = 0.0F; That would make all of the sounds at 0 volume, although I'm pretty sure that they would still play in the background, although the script reference (http://unity3d.com/support/documentation/ScriptReference/AudioListener-pause.html) for AudioListener.pause says that its the same as setting the volume to 0.

Try this script in replace of your current one, it's a bit of a modification:

This is the first time I have really ever programmed in C#!!!!!!!!!!!, at first it didn't work, but that was only because of the variable type, it had to be type 'bool', and I didn't specify the type. But after I realised it didn't work, I wrote it in JavaScript for you, so now you got both!!!

C#:

public bool muted = false;

void OnGUI() { if (GUI.Button(new Rect(10, 10, 100, 50), "Sound On/Off")) { if(muted == false){ AudioListener.volume = 0.0F; muted = true; } else{ AudioListener.volume = 1.0F; muted = false; } } }

JAVASCRIPT:

var muted = false;

function OnGUI(){

 if(GUI.Button(new Rect(10, 10, 100, 50), "Sound On/Off"))
 {
     if(muted == false){
     AudioListener.volume = 0;
     muted = true;
     }
     else{
     AudioListener.volume = 1;
     muted = false;
     }
 }

}

Hope this helps

Comment back if you need more help!!!!

-Grady

Comment
Add comment · Show 2 · 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 mEX · Sep 30, 2011 at 01:39 PM 0
Share

Great, thanks. It works. They should change the line in the reference, that's saying pause and volume=0 would be the same :D

avatar image Grady · Sep 30, 2011 at 02:21 PM 0
Share

That's good! I'm glad I could help you!!!!

-Grady

avatar image
0

Answer by funasylum · Feb 16, 2013 at 07:08 PM

I agree they should change the manual for AudioListener.pause. It is not the same as setting AudioListener.volume = 0f for the exact reasons outlined above (NEW sounds don't get set to zero). This is confusing and definitely wasted me some time.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Audio: -3db automatic attenuation on any audio playing? 0 Answers

Intensity of sound. -1 Answers

Sounds appear on wrong side. 0 Answers

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

mute / unmute helps 2 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