
https://www.youtube.com/watch?v=Fxrt08AkRYo&feature=youtu.be
Unity If statement

We use conditional statements all the time in real life. The Unity if conditional statement is used to conditionally execute logic depending on a condition or set of conditions. For example, suppose you go to your favorite restaurant and you ask for what you always eat there –
Fish & Chips
The server lets you know that you can’t order that since they’ve run out of Fish and to please choose something else. So you order your second best choice –
Pizza Another example:
If
you do you’ve done your homework only then can you play game.
Else
you need to finish your homework first.
In your code when you're making games you can control the way your program behaves/executes with conditional statements. If conditional statements can control the output of your program based on whether something isTrue
orFalse
.
Conditional statements are often used with comparison and equality operators to conditionally execute code in your game.
There are 3 conditional statements that you can use:
1. If
2. Else
3. Else if
Useif
to specify a block of code to be executed, if a specified condition is True. Keep in mind that the code inside the If conditional statement will only execute if the condition is true. If the conditiona is false, then execution is skipped and there is nothing to do.
Syntax
if(your condition here){ //code to execute ONLY if the condition is TRUE }