Creating A Modular Powerup System

Whether your character is becoming overwhelmed with zombies, a fleet of inter-galactic pirates or a hail of gun fire, a powerup can make the difference between life and death.

The more variety of powerups you create, the more options a player has…but it can also mean more headache if not implemented in a modular format.

For example, let’s say that you want a firing upgrade and also a speed boost for your player:

It wouldn’t really make sense to have multiple scripts for each upgrade…especially if you have 10s or even 100s of powerups. If you were to create a new script for every one, you would at best limit the number of powerups and at worst, make it extremely difficult to troubleshoot any bugs. In both cases you can cripple the play experience.

A better solution is to have one script for all powerups with a unique id or enum that differentiates the powerups:

Seeing as each powerup has the attributes in terms of speed/collision/etc, we can use this to our advantage by passing a unique qualifier to the player to activate the specific powerup.

First we can add the prefab for each powerup to our player:

Then we create a public method that can be accessed by the powerup game object:

Here we have the public method calling a coroutine in order for us to allow for a set duration of the powerup.

Finally we have the powerup script with a switch statement which is called when the collider enters the player:

--

--

--

Unity Developer

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

Recommended from Medium

The untestable enum switch in Java

Re: Avoid backing properties for LiveData and StateFlow

The golden rules of software (part 1 of 3)

Optimization in Python — the Interning Technique for Improved Performance

How to Dockerize your HashiCorp Vault set up with nginx reverse proxy

How WhatsApp Bot is helping us improve customer support experience

What are the main challenges faced in ERP Testing?

district0x Dev Update - May 26th, 2020

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
Mike Brisson

Mike Brisson

Unity Developer

More from Medium

Using Version Control With Unity

How to Remove a Large File from Commit History in Git?

Improving Upon Selection Highlighting in Our Game — Part 1

Commit with Git!