Journal 19 — Modular Powerups, Unity Practice

As part my game development, we have added two power ups, and I getting close to add a third. If you recall, we have a spawning function for power ups that is currently written only for the tripleshot.

To make the function modular, such as if we wanted 5 or 10 different power ups over all the game levels, we can use an array to store all the power up game objects.

In the example below, we add a new array GameObject[] powerUps, and show it in the Inspector. From there, we can specify the size in the Inspector (three total power ups for now), and delete the other individual game objects.

SpawnManager script, new array variable
SpawnManager script, clean up some variables no longer needed
Unity Inspector — Array size and add game objects

The spawn fuction for the power ups is modified using a random integer for 0, 1, and 2 to instantiate the power up randomly.

SpawnManager script — spawn power ups, change to randomize the power up spawned

Finally, we can test the gameplay to see if the power ups randomly spawn and drop to collect.

Unity Playmode — different power ups spawn correctly

Thank you for stopping by!

--

--

--

An Engineering Manager consultant who is seeking additional skills using Unity 3D for game and application development.

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

Recommended from Medium

Looking back at my 2019: Talks, Blogs, and Open Source

2020

Object Oriented Programming(Oops)

Auto Class Diagram In Python

How to Root Micromax In note 1 with Magisk without TWRP

PHP Web Developer Services a Must to Your Business’s Success

Don’t let someone who doesn’t know UI to tell you how to do it.

Set Up GitLab CI for Rails Applications

Getting started with RAPIDS on AWS ECS using Dask Cloud Provider

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
Chris Nielsen

Chris Nielsen

An Engineering Manager consultant who is seeking additional skills using Unity 3D for game and application development.

More from Medium

Making a Hack’n’slash #1: Moving and following our hero

Modular Power-Ups in Unity

Day 111: Introduction to Tilemap in Unity

Intelligent Camera Switching Using Clearshot Cameras