S
S
Soldat22832020-12-17 20:09:34
Unity
Soldat2283, 2020-12-17 20:09:34

There are sounds on the PC, when compiling for android, the sounds disappear and the button to turn them on is not pressed at all, how can I fix it?

There are sounds on the PC, when compiling for android, the sounds disappear and the button to turn them on is not pressed at all.
Here is the button script:

public void MusicWork(){
        if(PlayerPrefs.GetString("music") == "No" && gameObject.name == "Music") {
            GetComponent<AudioSource>().Play();
            PlayerPrefs.SetString("music", "Yes");
            GetComponent<Image>().sprite = musicOn;
        }
        else if(PlayerPrefs.GetString("music") == "Yes" && gameObject.name == "Music"){
            PlayerPrefs.SetString("music", "No");
            GetComponent<Image>().sprite = musicOff;
        }
    }


Here is an example button script with sounds:
if (PlayerPrefs.GetString("music") == "Yes")
            GetComponent<AudioSource>().Play();

How can this be resolved?

UPD: I did a check and realized that if you remove the buttons with an example from the script, then there is music, then there is a problem with the mute button if (PlayerPrefs.GetString("music") == "Yes")

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Soldat2283, 2020-12-17
@Soldat2283

It helped me to insert PlayerPrefs.Save() at the end of the button code

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question