Journal 39 — Change Balance of Spawn Power Ups in Unity

Chris Nielsen
2 min readJun 6, 2021

--

This article is about a modification to the probability of what power ups spawn.

The earliest version of the spawn function for power ups consisted of a random value generated based on the ID, which would spawn the power up directly.

Unity C# script for SpawnManager, first approach to spawn power ups

I expanded this spawn routine with all the power ups in game, and used a random number generator at the start of each spawn cycle. After this condition is passed, I then used a similar approach as above with selection of the power up using the power up ID in condition statements. Essentially, this approach adds a weighting factor that favors the spawning of more basic power ups [0] through [4], and makes it rarer to spawn the special attack [5] and the negative power up [6].

Unity C# script for SpawnManager, modified way to spawn power ups

The final version of this approach expands this weighting function so that all of the seven power ups can be customized by the user to a preferred rate of spawning. In this version, a health power up and special attack are the rarest.

Unity C# script for SpawnManager, final expanded version of approach to spawn power ups

Thank you for stopping by!

--

--

Chris Nielsen

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