Let’s go over the implementation of a simple charge meter for the speed boost power-up in the space shooter.
Add an Image object called to the UI which will be the background for the charge meter. Add another Image object as a child of the first image and call it fill. Set image type tio filled. Also a Text object as a child of the first image.
Open the UIManager script and a private Image for the fill image. Also add a public function that will handle the fill amount:
Open the Player script and add two floats for the thruster charge:
Amend the SpeedBoostCooldown function to no longer be a coroutine and instead cool down by reducing the charge with Time.deltaTime:
In the power-up switch statement reset the charge based on max charge:
Amended the ActivateThrusters to allow no longer be unlimited and get disabled if there is no charge left. You can also call the SpeedBoostCooldown from here or from Update if you prefer:
Lastly, add the fill image to the UIManager script in the inspector: