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 Uping · Sep 15, 2014 at 10:09 AM · soundmusicvolumemute

Mute volume / sound problem

okay my problem is when i press the mute button it works fine and unmute is fine but the problem is ive set it with a picture button but what happens is when I mute it and go to the next scene and go back again the volume is still muted but the button for it is for not muted okay here's my code

 void OnGUI(){
 if(yMute){
             if (GUI.Button(new Rect(100, 10, 100, 50), "",Y))
             {
                 AudioListener.volume = 0.0F;
                 muted = true;
                 nMute = true;
                 yMute = false;
             }
         }
         if(nMute){
             if (GUI.Button(new Rect(100, 10, 100, 50), "",N))
             {
                 AudioListener.volume = 1.0F;
                 muted = false;
                 nMute = false;
                 yMute = true;
             }
         }
     
     }
 
     void Start () {
         yMute = true;
 
     }
     
     // Update is called once per frame
     void Update () {
         if (yMute == true) {
             nMute = false;
         }
         else {
             nMute = true;
         }
     }
 }



so what I need is when i press my mute button the picture will change for the unmute and when i press it again the unmute will change for the mute picture it works fine but when i go to the next scene and go back here again the volume is muted but my button is for not muted so how can i fix that ? please help me 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
1
Best Answer

Answer by VincentDB · Sep 15, 2014 at 11:06 AM

The problem is that your using multipe variables to detect if user have alredy muted or not the sound. And you reset to false yMute variable at Start, so when you back to the scene, yMute is set to true, but nMute keep his old value.

Use only one variable would be better, something like:

 void OnGUI()
 {
     if(!isMuted)
     {
         if (GUI.Button(new Rect(100, 10, 100, 50), MuteImage))
         {
             isMuted = true;
             AudioListener.volume = 0.0F;
         }
     }
     else
     {
         if (GUI.Button(new Rect(100, 10, 100, 50), unMuteImage))
         {
             isMuted = false;
             AudioListener.volume = 1.0F;
         }
     }
 }
Comment
Add comment · Show 6 · 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 Uping · Sep 15, 2014 at 11:22 AM 0
Share

thankyou but, still wont work it wont even make the volume go to 0 i dont know why and when I press it its good the button is changing but when i go to the next scene with the un$$anonymous$$uteImage and go back its already changed to $$anonymous$$uteImage.....

avatar image VincentDB · Sep 15, 2014 at 11:43 AM 1
Share

Try to save a value.

 void OnGUI()
 {
 
     if(PlayerPrefs.GetInt("Is$$anonymous$$uted") == 0)
     {
         if (GUI.Button(new Rect(100, 10, 100, 50), $$anonymous$$uteImage))
         {
             PlayerPrefs.SetInt("Is$$anonymous$$uted", 1);
             AudioListener.volume = 0.0F;
         }
     }
     else
     {
         if (GUI.Button(new Rect(100, 10, 100, 50), un$$anonymous$$uteImage))
         {
             PlayerPrefs.SetInt("Is$$anonymous$$uted", 0);
             AudioListener.volume = 1.0F;
         }
     }
 }
avatar image Uping · Sep 15, 2014 at 12:33 PM 0
Share

worked like a charm thank you so much made my life easier :)

avatar image Uping · Sep 15, 2014 at 12:39 PM 0
Share

the only problem now is when the game restarts it goes back with sound

avatar image VincentDB · Sep 15, 2014 at 12:50 PM 1
Share

If you want keep player settings for next restart game, you have to save this setting by:

 PlayerPrefs.Save();

You can use this function by only one call on the function:

void OnApplicationQuit() { PlayerPrefs.Save(); }

Np and good continuation !

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Why is this script not working? 1 Answer

Audio slider for multiple scenes. 2 Answers

How do I have separate volume sliders for sound fx and music? 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Why is my backtrack's volume getting lower? 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