Adding Common and Rare Powerup Spawn Waves to 2D Galaxy Shooter in Unity!

Objective: To add 2 coroutines that handle the common and rare spawning powerups.

It is time to now bring some balanced spawning to our existing common and rare powerups and we are going to complete this by simply using our existing SpawnPowerupsRoutine() coroutine from within the “SpawnManager” script. There is no changes to where this coroutine is getting called (from within the SpawningEnemiesRoutine() coroutine in the “SpawnManager” script):

Creating some Variables

Let’s create some serialized variables of type GameObject so we can drag and drop the powerup prefabs into the Unity Inspector. We will create an array of 4 for the common powerups and 3 for the rare as shown below:

Now let’s dive into the coroutine that is going to handle the powerups spawning:


Here we will initially pause for 3 seconds at the start of the wave before the first powerup drops.

Then we will jump into a while loop that will continue to run until the player dies. Firstly, we are going to get a random number between 3 and 7 which is the random timer for when the next powerup will spawn, then we are also going to create a random Vector3 location for where the powerup will spawn and finally a random number between 0 and 100 which is going to be our % chance to spawn a common or rare powerup.

Now we are going to complete some If, Else-If checks that are going to see if the random number is between 0 and 30 (~30%) and then spawn a rare random powerup. Else-if the number is between 31 and 100 (~70%) then spawn a random common powerup.

Once it has spawned the powerup we will then wait for the _powerupTimer before running through a while loop again.




Passionate Unity Game Developer

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

Recommended from Medium

Blockchain: Block Structure

How To Set Up a Firewall Using FirewallD on CentOS 7

SREcon17: Brave new world of site reliability engineering

7 Ways to Earn Money From Coding and Programming

Introduction to MongoDB and Spring Boot Integration

25 Ruby Gems I use in almost every SaaS project

Kickstart Your Kubernetes Cluster on Amazon EKS With Terraform Like a Boss in 7 Steps

‘Stored Procedure’ Structure in SQL Server

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 Hilton

Chris Hilton

Passionate Unity Game Developer

More from Medium

Using the Layered Lit Shaders to mix Texture Maps in Unity3D

Instantiate and Destroy Game Objects in Unity

Understanding the Body Settings in Cinemachine Virtual Cameras

Galaxy Shooter 2D — Super Laser