How do I get a Toggle Button to work using a custom GUI skin?

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

All I literally had to do to fix this problem was to remove the ‘if’ statement in:

if (toggleImg = GUI.Toggle(new Rect((Screen.width / 2.6f) - 30, Screen.height / 3, 60, 50), toggleImg, "", customButtonStyle3))

TO: toggleImg = GUI.Toggle(new Rect((Screen.width / 2.6f) - 30, Screen.height / 3, 60, 50), toggleImg, "", customButtonStyle3);

Can’t believe it took me this long to figure that out… I hope this helps anyone who has a similar problem. How was I supposed to know it was because it was in an ‘if’ statement, when every other button I have works with an ‘if’ statement? I assume this is how GUI toggles work.