1

I have a GUITexture "Settings" and I want when I'll click on it, some settings to show up, for example music on/off.

enter image description here

You click on the settings button and the music button appears. And by clicking on the music button you can mute/unmute the music in the game.

How can I do this?

Steven
  • 166,672
  • 24
  • 332
  • 435

1 Answers1

0
private boolean displayMusic = false;
private boolean musicOn = true;
void OnGUI() {

    if (GUI.Button (new Rect (Screen.width / 2, Screen.height / 2, 150, 50), "Settings")) {
        displayMusic = true; //If the settings button is clicked, display the music
        // Here you could replace the above line with
        // displayMusic = !displayMusic; if you wanted the settings button to be a
        // toggle for the music button to show
    }

    if (displayMusic) { //If displayMusic is true, draw the Music button
        if (GUI.Button (new Rect (Screen.width / 2, Screen.height / 2 + 50, 150, 50), "Music " + (musicOn ? "On" : "Off"))) {
            musicOn = !musicOn; //If the button is pressed, toggle the music
        }
    }
}

I hope this helps!

Zach
  • 4,652
  • 18
  • 22
  • If you think the answer has correctly answered the question, please consider marking it as correct. Thanks :). – Zach Jul 18 '14 at 13:11