Next powerup, the shield…

Sherry Fisher
3 min readAug 11, 2023

--

Last time, I finished creating the speed powerup. Today I am working on the third powerup, the shield.

Just like with the prior two powerups, I added the new powerup to my hierarchy and renamed it. I adjusted the scale and added the collider and rigidbody, again making sure to set gravity to 0 and checking IsTrigger. I also added it to the foreground so that it appears in front of the background image.

Next I assign the powerup script to my new powerup and set the powerup ID to 2.

Next, I add the animation.

Now that it is setup, I drag it to the powerup prefab folder and remove it from the hierarchy.

I now need to add it to the spawn manager. First I add it to the Spawn Manager Script in the Inspector.

Next, I need to adjust the range in my SpawnManager script in Visual Studio to account for the added powerup.

Next I test the game to make sure all three powerups are spawning, which they are, but currently collecting the shield has no effect as I still have to create the script for its behavior.

In this case, the shield is going to give the player invincibility for one hit and then the shield is deactivated. I first work on adding the shield to the player script.

Then I update switch statement in the Powerup script to include the shield powerup. I then test to ensure the shield is working as expected before moving on.

I bring the shield gameobject into the hierarchy. I make it a child of the Player so it moves around with the Player.

I return to the player script and add the _shield variable and add code to turn the shield on and off.

Now time to test again to make sure everything is working as it should be.

Last step is now to animate the shield.

And now once again, test. Now we have three working animated powerups!

--

--