Time for action – create if statements with more than one condition to check
Modify
LearningScript
as shown in the next screenshot.Save the file.
In Unity, click on Play.
Note
Notice line 11 is using the AND operator, and line 16 is using the OR operator.
What just happened?
Here is the output you get in the Unity Console:
Code analysis:
The code on line 8 and its description:
bool theBearMadeBigPottyInTheWoods = true;
A
bool
variable is declared and assigned the value oftrue
.The code on line 9 with its description:
int temperature = 40;
An
int
variable is declared and assigned the value40
.The code on line 11 with its description:
if(temperature >= 35 && theBearMadeBigPottyInTheWoods)
An
if
statement to test if both conditions aretrue
.The first test is checking if the
temperature
is greater then, or equal to,35
.The value stored in
temperature
is40
, so this condition is true.The value stored in
theBearMadeBigPottyInTheWoods
is true. Therefore the first condition and the second condition...