1

我有一个 GUITexture“设置”,当我点击它时,我想要显示一些设置,例如音乐开/关。

在此处输入图像描述

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

我怎样才能做到这一点?

4

1 回答 1

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
        }
    }
}

我希望这有帮助!

于 2014-07-18T12:16:09.840 回答