Journal 44 — Player update in Unity, Press C to Collect Power Ups!
In this challenge, we can add a new skill to the player, so that if there’s a power up on screen, the player can press “C”, and the power up will automatically move to the player.
In the Player C# script Update method, we add a check for when the player presses the “C” button, then we create a reference to the Powerup script, and call a function that the player can collect a power up.
In the Powerup script, we set the bool to true.
In the Powerup script Update method, we redo the original downward movement to two different options: If the player has pressed “C”, the power up’s transform position is changed to move towards the player. Otherwise normal movement is downward.
Then when the power up is close to the player, we start a coroutine to cool down, and also set the collect power up bool back to false.
Finally, you can see this in action.
Thank you for your time!