I can’t figure out how to make a working mute button using gui.toggle, and it’s driving me insane. Here’s some of the code I’ve taken out of the script:
public GUISkin guiSkin3;
public Font yourFont;
GUIStyle customButtonStyle3;
private bool toggleImg = false;
void OnGUI() {
GUI.skin = guiSkin3;
if (customButtonStyle3 == null) {
customButtonStyle3 = new GUIStyle(GUI.skin.toggle);
customButtonStyle3.font = yourFont;
}
if (toggleImg = GUI.Toggle(new Rect((Screen.width / 2.6f) - 30, Screen.height / 3, 60, 50), toggleImg, "", customButtonStyle3))
if (toggleImg == false)
{
AudioListener.volume = 1;
}
else if (toggleImg == true)
{
AudioListener.volume = 0;
}
}
I’m able to mute the sound when I click the toggle button in the game, but when I click the toggle button again the sound stays muted. It’s as if ‘false’ doesn’t want to come back on, so to speak. I’ve tried the toggleImg = !toggleImg style of on/off but that is a worse result (unless I’ve written that wrong too). I can’t for the life of me figure out why this won’t work. I can only think it’s because I’m using a custom gui skin to replace the default toggle graphic.
Any help is appreciated. Thanks