我进行了一些检查以查看屏幕是否处于 Activity 状态。代码如下:

if (GUI.Button(new Rect(Screen.width / 2 - 10, 50, 50, 30), "Rules")) //Creates a button
    {
        if (ruleScreenActive == true) //check if the screen is already active
            ruleScreenActive = false; //handle according to that
        else
            ruleScreenActive = true;
    }

有什么方法-每当我单击按钮时-反转ruleScreenActive的值?

(这是Unity3D中的C#)

最佳答案

您可以通过否定 boolean 值来摆脱if/else语句:

ruleScreenActive = !ruleScreenActive;

09-30 17:18