Time for action – create a couple of if statements
The if statements work by determining whether a condition inside a pair of parentheses is true or false.
- Modify
LearningScript
as shown in the next screenshot. - Save the file.
- In Unity, click on Play.
What just happened?
Here's the output in the Unity Console:
Code analysis:
- The code on line 8 is as follows:
bool theBearMadeBigPottyInTheWoods = true;
This Boolean variable is declared and assigned the value of
true
. - The code on line 10 and its description:
if( theBearMadeBigPottyInTheWoods)
An
if
statement to test if the condition between the parenthesis istrue
orfalse
.The variable
theBearMadeBigPottyInTheWoods
is storing a valuetrue
, therefore.The code block on lines 11 to 13 is executed, as shown in the Console screenshot.
Using the NOT operator to change the condition
Here's a little curveball to wrap your mind around, the NOT logical operator. It's written in code using an exclamation mark. This makes a true condition false...