Journal 19 — Modular Powerups, Unity Practice

Chris Nielsen
2 min readMay 2, 2021

--

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!

--

--

Chris Nielsen
Chris Nielsen

Written by Chris Nielsen

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

No responses yet