Objective: Creating an object that activates double speed for the player.
First we will add the sprite of the speed powerup and give it the same properties as we gave our trippleshot since this is just another powerup that will just activate a different method and coroutine. …
OBJECTIVE: Create a switch statement which will be more efficient than multiple else if statements
First thing we will do is remove the else if statements, then we will add the switch. Each switch will require a case which will first be checked then broken, creating a more efficient checking method for our power ups.
Animating in unity is very simple. First select the object we want, then go to window and select animation. Then we will add the animator to the bottom of our screen, next to our game window.
To create an animation, we will click create, create a new folder for animations and save our Tripleshot animation. To create the animation, we will simply click the red record button, then we will drag and drop our sprites in order into the animation window. The animation loops automatically, so we do not need to do anything else.
Now that we have the basic code for how the powerup should function, we need to implement its behavior. We will do this by using a similar method to our damage method. In this case, we need a collision to change the state of our variable from false to true. This will make it active for 5 seconds and then switch it back to false, ending our coroutine.
The other part of the code is on the variable itself, which just communicates with the code above upon colliding with the player and preforming a null check.