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 /
  • Help Room /
avatar image
0
Question by meshari94 · Sep 02, 2015 at 04:32 AM · unity 5uimute

Changing Music On Icon To Off and saving the preference

Hi,

Finishing up a game i have been working on for a while, i came the problem of changing the icon of the mute music. I have the icon images and everything, however i am not able to find a way that changes the music icon to a music-off icon when pressed. So basically, what i have now is a UI button that when pressed, mutes the music in the game. However i can't figure out how to change the icon when the music has been muted and to save that preference so that when the player changes scenes and comes back to the scene where the icon is, it should show a music-off icon if it had been muted.

I hope i was a bit clear with my description :).

Thanks.

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
1

Answer by NCPLNaveen · Jan 13, 2016 at 09:35 AM

Hey @Meshari94, Even i was having the same problem, I come up with a solution, try this create a Empty game object in the scene and add this script which im going to write down.

using UnityEngine; using System.Collections; using UnityEngine.UI;

public class Soundonandoff : MonoBehaviour {

 public Button b;
 public  bool musicMute;
 public Sprite musicOn;
 public Sprite musicOff;
 
 void Start () {
     musicMute = false;
     if (AudioListener.volume == 1) {
         b.image.sprite = musicOn;
     } else {
         b.image.sprite = musicOff;
     }
 }
 
 public void Musiconandoff(){

     musicMute = !musicMute;
     if (musicMute) {
         AudioListener.volume = 0;
         }
     } else if (!musicMute) {
         AudioListener.volume = 1;
         }
     }
 }

}

and then create a button in UI and place it at correct location. Then give the above script to created empty game object and assign the above created button as well as the images that you want to display to the script. On the button you will find OnClick() function add the empty gameobject and also the function Musiconandoff() function. thats it

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 FailureToAdapt · Jan 04, 2017 at 06:37 PM 0
Share

This does not work. It does not change the image and it doesn't correct the issue the OP was having of saving the previous state of the image between scenes.

avatar image hahahihiwahaha · May 07, 2019 at 04:11 PM 0
Share

it works for the music but it doesn't change the icon. but when I open the scene again and the icon changed. For ex: i mute the music, the icon is still the on icon and then I went to another scene. And I come back to that scene but the icon is the off icon. if I click it, still the same icon

avatar image
0

Answer by dicsiroland9 · Nov 05, 2019 at 04:31 PM

I have the same problem...

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

34 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 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

How to change a score 1 Answer

How can I extend an UI Component and change it's default values when added on editor? 0 Answers

UI buttons sometimes does not detect touch 0 Answers

Text Component Size is not Adjusting 1 Answer

MapNav - Geolocation Toolkit Gives Wrong Long and Lat 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