I’ll show you an example. Suppose we want a function that display two messages if and only if the variable “a” is bigger than 10.
void FunctionOne() {
int a=0;
if (a>10) {
Debug.Log("Good news!");
Debug.Log("A is bigger than 10!");
}
}
void FunctionTwo() {
int a=0;
if (a>10)
Debug.Log("Good news!");
Debug.Log("A is bigger than 10!");
}
These two functions look very similar but the second one always print “A is bigger than 10!”, also when the variable “a” is zero. The reason is that the compiler automatically puts brackets for you when you don’t put them. It puts them only around the first instruction (the “Debug.Log(“Good news!”);” one) leaving the second instruction out from the if statement.
In other words, the compiler automatically convert FunctionTwo to
void FunctionTwo() {
int a=0;
if (a>10) {
Debug.Log("Good news!");
}
Debug.Log("A is bigger than 10!");
}
That is obviously different (in fact the second Debug.Log is always executed).
To avoid this type of bugs the rule is simple: you must always use the brackets.
He whant to say: with out brackets you can put just ONE line of code! So if your IF have just one line you dont need brackets…but code look more beather with them and easy to reed