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 11:47 PM · audiomusictogglekey

Audio Source will not "unmute" after toggling?

Hello,

I've been working at this for 2 days and I've had some great help, but it seems like something isn't working right. I am using this script to toggle the mute parameter on an Audio Source:

 // Mutes-Unmutes the sound of this transfor each time the user presses escape.
 
     function Update() {
          if(Input.GetKeyDown(KeyCode.Escape)) {
              if(audio.mute)
                 audio.mute = false;
             else
                 audio.mute = true;
         }
     }

This script works perfectly for muting the audio source, but it doesn't seem to unmute the audio. Basically, if I start the scene with the mute button ticked on the audio source, it will not unmute the audio source and toggle the mute button each time I press escape. The check-mark on the mute parameter stays ticked on the audio source and no audio plays. If anybody could please help me out on this one, I would really appreciate it! Trust me, I've spent a ton of time on this one, and I just can't figure it out! THANK YOU SO MUCH for your help!!

Comment
Add comment · Show 5
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 cmpgk1024 · Nov 19, 2013 at 12:06 AM 0
Share

Did you try using Get$$anonymous$$eyUp ins$$anonymous$$d of Get$$anonymous$$eyDown? It could be rapidly toggling on and off.

avatar image Peanut97 · Nov 19, 2013 at 12:08 AM 0
Share

I'll give it a go. Be right back.

avatar image Peanut97 · Nov 19, 2013 at 12:10 AM 0
Share

Is there a way to make it toggle the mute when the button is not held down, just tapped?

avatar image cmpgk1024 · Nov 19, 2013 at 12:13 AM 0
Share

That's what Get$$anonymous$$eyUp should do. Get$$anonymous$$eyDown will return true whenever the key is held down, so you'll be toggling it constantly whenever the escape key is held. If you use Get$$anonymous$$eyUp it won't return true until the key is released, so that should work if you want to have it toggle when the button is tapped.

avatar image Peanut97 · Nov 19, 2013 at 12:16 AM 0
Share

I changed it to Get$$anonymous$$eyUp and it seems like the audio will play whenever the button is held. I'm sure what's going wrong.

2 Replies

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

Answer by TargonStudios · Nov 20, 2013 at 05:09 PM

This script i made is rather crude. Currently, i can't test any script myself so i made it a simple one for you.

Replace if(audio.mute) and beyond with:

 if(audio.mute == false){
 MuteAudio();
 }else{
 Unmute();
 }
 
 function MuteAudio(){
 yield WaitForSeconds(0.01);
 audio.mute = true;
 }
 
 function UnmuteAudio(){
 yield WaitForSeconds(0.01);
 audio.mute = false;
 }

Hopfully the script works. Hope this helps!

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 Peanut97 · Nov 23, 2013 at 04:33 PM 0
Share

Thank you so much for your help!

avatar image
0

Answer by algaib · Aug 06, 2017 at 07:52 PM

Add this script below to the audio source, then drag the audio source itself into the public variable on the script component, then drag the audio source into the 'On Click()' part of the button. The button will then toggle the 'mute' button on the audio source.

 public AudioSource appMusic;

 public void MusicMute()
 {
     appMusic.mute = !appMusic.mute;
 }
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

20 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

Related Questions

Pausing and playing audio on key press? 1 Answer

Can anyone help me invert this simple script? 2 Answers

how do i play a sound if i press a particular key? 2 Answers

Music will not change when an event triggers it 3 Answers

Stream music in Unity mobile 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