Switch statements and Enums!

Switch statements are very convenient when you want to compare a single nonstatic variable to determine which course of action should be taken. They act similarly to chained if-else statements but tend to be regarded as something a bit more cleaner and better performance-wise.

An example of the chained if-else statement.
  • Each ‘case’ must end with a ‘break;’ command, which indicates the end of each case.
  • You can also use a ‘default’ case, which is called when the variable's value does not match any other case values.
  • The enum values start at 0, counting up with each enum item. But you can also set the value of an object manually.

Aspiring and eager beginner Unity developer