- Home /
[Not Fixed] Music doesent mute, please help
Hello i have a problem i have a unmute button that gonna mute my background music but it doesent mute it, it worked until i upgraded unity 4.0 to 4.2 this is my script:
public bool muted = false;
string buttonTextaudio = "MUTE";
if (GUI.Button(new Rect(655, 435, 125, 25), buttonTextaudio, style))
{
audio.PlayOneShot(buttonsound);
if(muted == false)
{
AudioListener.volume = 0.0F;
muted = true;
buttonTextaudio = "UNMUTE";
}
else
{
AudioListener.volume = 1.0F;
muted = false;
buttonTextaudio = "MUTE";
}
}
I have seen more people that have this problem and its a Unity 4.2 bug
What does 'not work' mean? Does it give an error? Does it always make sound? Does it never make sound?
it does not gives an error, i have a background music and when i click mute it doesent mute the music
Along the right side of this page is Related Questions. Look through those, you might find your answer there.
Does the button text change when you click the button? If it does and the audio isnt muted, then i bet you are setting the audio listeners volume from another script in your project.
Answer by DaveA · Sep 15, 2013 at 01:53 AM
This line:
AudioListener.volume = GUI.HorizontalSlider(new Rect(432, 420, 600, 30), AudioListener.volume, 0.0F, 1.0F);
is going to override your 0 or 1 on every tick. That's what's wrong. I don't know how it worked before. Maybe now you can't set that volume in the same frame twice? In any case, it's better UI to explicitly have a Mute button that does NOT change the volume. Otherwise, when you unmute, volume will go to full, which is probably not wanted.
Better to have a boolean 'mute' and new float value which holds the volume level, and use that for the slider, set it only when mute is false. When mute is true, set AudioListener volume to 0, when mute goes false, set that to the new float value.
I tryed to remove that line and try again but it didnt worked also i removed all my audiolistener in my script and tryed making a simple mute button wich gonna mute the sound and sends a print log but only the print worked
if (GUI.Button(new Rect(655, 435, 125, 25), "mute", style))
{
AudioListener.volume = 0.0F;
print("muted");
}
$$anonymous$$ake the mute button a GUI.Toggle ins$$anonymous$$d
public bool muted = false;
float volume = .5f;
string buttonTextaudio = "$$anonymous$$UTE";
bool last$$anonymous$$ute = muted;
muted = GUI.Toggle(new Rect(655, 435, 125, 25), muted, buttonTextaudio, style))
if (muted != last$$anonymous$$ute)
{
audio.PlayOneShot(buttonsound);
if(muted == false)
{
AudioListener.volume = 0.0F;
muted = true;
buttonTextaudio = "UN$$anonymous$$UTE";
}
else
{
AudioListener.volume = volume;
muted = false;
buttonTextaudio = "$$anonymous$$UTE";
}
}
GUI.Label(new Rect(330, 414, 100, 30), "$$anonymous$$aster Volume:");
float lastVolume = volume;
volume = GUI.HorizontalSlider(new Rect(432, 420, 600, 30), volume, 0.0F, 1.0F);
if (lastVolume != volume && !muted)
AudioListener.volume = volume;
@DaveA the line "muted = GUI.Toggle(new Rect(655, 435, 125, 25), muted, buttonTextaudio, style))" gave me a error so i changed the )) at the end to ); and fixed the error but now i when i click mute nothing happends and it doesent change to unmute
Your answer
![](https://koobas.hobune.stream/wayback/20220613114146im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Problem with Unity 4.1 - AudioSource.ignoreListenerPause not working? 1 Answer
sound too low in Android devices 0 Answers
Audio volume problem? 2 Answers
AudioListener (v4.6) missing volume 1 Answer