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:

--

--

--

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

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Career changing to software engineering, a new world of culture

How To Get Employees To Use New Enterprise Software

Building and Testing with Unity (2D Space Shooter)

Ever since I was a little boy, I have only ever wanted to be a Doctor.

Top Performance Testing Tools

Running Arachni Web Application Scanner

IoT:- An Introduction

Do You Still Need a Computer Science Degree in 2021?

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.

More from Medium

Hidden Shortcuts to Make Level Design Easier

Unity and Object movement

2D Mobile: Setting Up The Player

2D Mobile Game: Player Run Animation