Skip to main content

Introduction to C# in Unity #11: Unity If conditional statement

By February 16, 2021July 17th, 2022No Comments
If Conditional

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:


 you do you’ve done your homework only then can you play game.


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 is True or False.
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

Use if 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.


if(your condition here){

//code to execute ONLY if the condition is TRUE



Leave a Reply