- Home /
what is a boolean
I am a noob in Unity and I`ve been watching youtube tutorials and I have noticed some people use variables of tipe boolean and I can`t find out why.
Answer by slayer29179 · Jun 17, 2012 at 02:06 PM
Boolean is a variable which can go two ways on or off :) so you can use it for switches, to enable something or detect items such as if the player hits a location the variable switch is true and if its true do something else it usually looks like so
var <variable name> = true ;
var <variable name> = false;
:) to detect them
if (<variable name> == true)
note: two equal signs to say if and 1 equal sign to say it does hope this helps :)
For reference, this type is called "bool" when using C# ins$$anonymous$$d of UnityScript.
Answer by Drakestar · Jun 17, 2012 at 02:06 PM
A boolean has 2 values: 0/1, or true/false. It's the simplest state that a computer can represent, and corresponds to "energy is flowing/is not flowing" (all computers are built around boolean logic). Theoretically, a BOOL can be represented in memory using a single bit, but for various reasons (ease of memory addressing and speed) it's usually 1 byte.
awesome thanks for the patience, as you can see im kind of a noob
Answer by QuarterMillion · Aug 16, 2021 at 09:18 PM
@Drakestar I feel like that is so backwards if something returns a value it should be true and its numerical representation should be 1.
If something does not return a value it should be false and its numerical representation should be 0 as no value was returned and it would line up more naturally with what you'd expect.
I propose this :
bool[] realbool = new bool[]{false,true};
yeah, i think he didn't put that much thought in order, 1 is true and 0 is false, but i guess it's a 9 year old post...so not that it will matter as much
Your answer
Follow this Question
Related Questions
Unity says there is no such thing as a boolean. 1 Answer
void cannot be used in a boolean context 1 Answer
Static variable error 2 Answers
Why can't I acces my global variable? 3 Answers
Played time? 2 Answers