GUI - Permanent Selection

I would like to have my active GUIStyle stay visible while it is actually active, in the sense of like a Sound Mute button. What is the best way to do so? I’ve been stuck with it for a little while.

Willing to elaborate if needed.

Thanks in advance!

The GUIStyle is a collection of custom attributes that defines the appearance of a single UnityGUI Control. So the GUIStyle itself is never visible. If you want to create a GUI button then use GUI.Button. You’ll get 2 screen buttons if you attach the following example script on an Empty GameObject:

And what exactly do you mean permanent? For instance, in the above example, the 2 buttons will be permanent in the scene as long as the GameObject that the screen is attached to is enabled (active). However, if you load a different scene and you want to make the button permanent also between scenes, you have to use DontDestroyOnLoad. So add the code in the following example, in the Awake() method of the script containing the GUI.Button code:

If this helps you please accept the answer (click the check mark icon). Otherwise, please clarify your question and elaborate.

UPDATE: The following script provides the functionality you need:

using UnityEngine;
using System.Collections;

//Create an empty GameObject in the hierarchy and attach this script

public class MuteButton : MonoBehaviour {

    public Texture ButtonSoundOn;  //Displayed when the sound is on.  When clicked will mute the sound
    public Texture ButtonSoundOff;  //Displayed when the sound is off.  When clicked will turn the sound on


    private bool soundOn;

    //If you need the Mute button to shown on all scenes, use the following code
    void Awake() 
    {
        DontDestroyOnLoad(gameObject);
    }

    // Use this for initialization
    void Start()
    {
        soundOn = true; //if the sound is on when the scene starts set this flag to true
    }

    void OnGUI()
    {
        if (soundOn) //Do this when the sound is ON
        {
            if (!ButtonSoundOn)
            {
                Debug.LogError("Please assign a texture on the inspector");
                return;
            }
            if (GUI.Button(new Rect(10, 10, 50, 50), ButtonSoundOn)) //display button with ButtonSoundOn Texture
            {
                //if the ON button is clicked, mute the sound
                //and set the flag to indicate the sound is OFF

                //code to mute sound

                soundOn = false;
            }
                
        }
        else //Do this when the sound is OFF
        {
            if (!ButtonSoundOn)
            {
                Debug.LogError("Please assign a texture on the inspector");
                return;
            }
            if (GUI.Button(new Rect(10, 10, 50, 50), ButtonSoundOff)) //display button with ButtonSoundOff Texture
            {
                //if the OFF button is clicked, turn the sound ON
                //and set the flag to indicate the sound is ON

                //code to turn the sound on

                soundOn = true;
            }
        }

    }
}