我不能倒置“一个布尔值? [英] Can I 'invert' a bool?

查看:141
本文介绍了我不能倒置“一个布尔值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些检查,看是否有画面激活。代码如下:

 如果(GUI.Button(新矩形(Screen.width / 2  -  10,50,50 30),规则))//创建一个按钮
{
如果(ruleScreenActive == true)而//检查屏幕是否已经激活
ruleScreenActive = FALSE; //根据该
,否则
ruleScreenActive =真正的处理;
}



有没有什么办法 - 每当我按一下按钮 - 反转的价值 ruleScreenActive



(这是Unity3D C#)


 <$ C $:h2_lin>解决方案

您可以通过否定布尔值摆脱你的if / else语句C> ruleScreenActive = ruleScreenActive!;


I have some checks to see if a screen is active. The code looks like this:

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

Is there any way to - whenever I click the button - invert the value of ruleScreenActive?

(This is C# in Unity3D)

解决方案

You can get rid of your if/else statements by negating the bool's value:

ruleScreenActive = !ruleScreenActive;

这篇关于我不能倒置“一个布尔值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆