Hello,
The default value of Friend boolean is false. Does !Friend means “Friend == false” or does it means a state that is opposite of current state. Example: Friend default is false so, not friend is opposite of false so “Friend == true”. I always thought !bool means bool==false. But a tutorial I’m learning seems off. So want to know.
public bool Friend = false; // variable declaration
if (!Friend)
{
do this code
}
public bool enemy = false; // in the example enemy is false
bool friend = !enemy; // NOT false is true so friend is true
In this code friend and enemy will always be the opposite as you can’t be enemies and friends.
_
An if() statement is only asking if the stuff inside the brackets returns true.
as !false is true (similarly !true is false) then “do this code” will occur.
You can actually test out more complex examples yourself:
bool test1 = !(true&&false); // true AND false is false. but !(true AND false) is true.
Debug.Log("test1: " + test1);
bool test2 = (true||false) && !(true&&false); // true OR false is true AND !(true AND false) is true
Debug.Log("test2: " + test2);
it’s good to understand how AND and OR work as when working with more complicated code you will likely use them. A final example assuming the booleans are set elsewhere in the code.