Weighted Enemy Spawn System

Today I add on to the spawn manager and balance out some enemies. The technique I used is exactly as I did when I balanced the power-up up spawn system. Here is the article for that which explains some things better. In this article, I will be going through this fairly quickly since it’s the same principle.

First, I created a table for the weight of my enemy prefabs. I also made my ‘_enemy’ GameObject reference an array. And also created an int variable for the total weight of the enemy table.

In ‘Start’ we need to get our ‘enemyTotalWeight’ using a foreach loop that will add each item value in the enemy table.

We will create a new function for how we choose our enemy.

Now, we’re going to alter the ‘SpawnEnemyRoutine’ coroutine that we previously had to better suit our changes. Pretty much just removing the spawning stuff and replacing it with the new function we just wrote.

Make sure you add your enemies in the inspector and set the values you want them to spawn at.