如何弹出GUITexture?

时间:2014-07-18 10:17:23

标签: c# unity3d guitexture

我有一个GUITexture"设置"我希望当我点击它时,会显示一些设置,例如音乐开/关。

enter image description here

单击设置按钮,将出现音乐按钮。通过单击音乐按钮,您可以将游戏中的音乐静音/取消静音。

我该怎么做?

1 个答案:

答案 0 :(得分: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
        }
    }
}

我希望这有帮助!