Balancing the Power-Up Spawns

Kyle W. Powers
May 17 · 3 min read

In this article, we will make it so that the Ammo Power-Up spawns frequently and the rest of the Power-Ups rarely.

In the SpawnManager script, we need to add some variables. First are two floats, one for the chance of Power-Ups in the uncommon array to spawn and the other for the rare array. Then we need a GameObject for the common Ammo Power-Up Prefab and two GameObject arrays for the uncommon and rare Power-Up Prefabs. The last variable we need is an int to keep track of how many rare Power-Ups have spawned in a Wave.

This method returns the selected Power-Up based on a random value between 0.0 and 1.0 or nothing if the Power-Ups shouldn’t be spawning. If the random value is greater than the uncommon chance, we return the common Power-Up Prefab. If the random value is less than or equal to the rare chance, we return a random rare Power-Up Prefab or the first if there is only one, and if the Wave has reached the maximum rare Power-Ups, we return the common Power-Up Prefab. For everything else, we return a random uncommon Power-Up Prefab or the first if there is only one.

Now to update the SpawnPowerUpRoutine to use the different groups of Prefabs. We need to call the SelectPowerUp method and store the returned GameObject for instantiation if it is not null. And set the number of rares spawned back to zero at the start of the Coroutine.

On the SpawnManager, you can see how the Power-Ups are sorted.

Each Wave, the Player gets a chance at a set number of rare Power-Ups, an opportunity for uncommon Power-Ups, and lots of Ammo.

Nerd For Tech

Nerd For Tech

NFT is an Educational Media House. Our mission is to bring the invaluable knowledge and experiences of experts from all over the world to the novice. To know more about us, visit https://www.nerdfortech.org/. Don’t forget to check out Ask-NFT, a mentorship ecosystem we’ve started

Kyle W. Powers

Written by

Unity Developer, Software Engineer, Game Designer

Nerd For Tech

NFT is an Educational Media House. Our mission is to bring the invaluable knowledge and experiences of experts from all over the world to the novice. To know more about us, visit https://www.nerdfortech.org/. Don’t forget to check out Ask-NFT, a mentorship ecosystem we’ve started

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

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