Switch Statements to the Rescue-Day 20

Objective: Learn how to write efficient, clean, and readable statements.

Switch statements have the same concept as a bunch of if/else statements. You use the keyword ‘switch’. You switch through a variable, which is the powerupID variable. You have a case for every outcome you’re checking. Inside switch(powerupID), you insert the cases. For case 0: player.TripleShotActive(); for case 1: Debug.Log(“Collected Speed Boost”); for case 2: Debug.Log(“Shields Collected”); You end each code statement with the ‘break’ keyword. If neither case 0,1, or 2 were an option you would use the ‘default’ keyword.

--

--

KW Development LLC

Seasoned, result-oriented, highly professional individual with a stellar record of expertise in back-end development and game development.