Switch Statements to the Rescue

Ok, let’s add a new PowerUp to our game. We need some shields to protect our player.

Our switch statement makes it a snap in Unity.

Picking up a PowerUp (from a 2dCollision), we can identify which PowerUp routine to execute based on the value held in the powerupID variable held on the Powerup.

Assigning the ID is done in the UI since we’ve Serialized the field:

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Richard Morgan

Richard Morgan

Unity and Flutter developer interested in creating mixed-reality applications.