Creating Modular PowerUp System Part 2

Upgrading our SpawnManager

Objective: We need to update our SpawnManager GameObject to randomly spawn from a set of powerups

If we wanted a quick method of implementing a spawn system we could use a switch statement like below. This works with most cases with a few options but if the number of powerups gets large then this statement can get out of control pretty quick.

Don’t over engineer — Unity has you covered

To simplify let’s use an array of GameObjects. An array is a data structure in C# that allows you to group a set of similarly typed items together. Each item would then be accessed with an index denoting its space in the data structure.

Coming from a background in Software Development, I knew that we would need the length before we could add items to it. Luckily Unity provides this functionality by default when it detects an array.

Since Unity is helping us out we can drop the above code down to 2 lines:

Reworking our Shield setup

Yesterday I instantiated the shield and parented it to the Player during instantiate. Here is our updated method of implementing the shield.

Doing it this way will remove our setup code in the Start method since we already are parented to Player and can set our scale through the Unity Interface.