Objective: Create a powerup that generates a negative effect for the player.
We have made a few powerups together, and all have one thing in common. They all help the player in some way. We need to balance the scales and create an objective that will hinder the player slightly in some way. I think in this type of game a good temporary handicap would be a speed penalty.
To begin I’m using the same sprite I used for the speed boost powerup and change it’s color to slightly.
Like every other powerup we’ve done so far, we need to attach the powerup script and add the components; rigidbody 2d, and circle collider 2d.
Now we need to assign an ID# on the inspector of the powerup and add it to the spawn manager list.
Open the powerup script and add this powerup to the switch statement.
Navigate to the player script and create the method you want the negative powerup to call.
I currently use three different variables to determine the speed of the player, so I am going to take all three of them and divide them in half with the speed multiplier variable.
Create an IEnumerator, have it yield the amount of time you want the negative effect to be active then multiply the speed variables by the speed multiplier to return them to normal.
For me, since I have two different spawn routines for my variables, I have to adjust those as well. I need to change the values I’m using on my random range.
With this we are done. Now we have a powerup that will hinder the players speed for a few seconds and those seconds can easily ratchet up the difficulty of our game. Don’t be afraid to experiment with this code, and I’ll see you in the next tutorial.