Player Missile Part 3!
Objective: Create a UI element to give the player a visual representation of how many missiles they currently have.
So far, we have created a missile for the player that targets an enemy and chasses them and explodes. We created ammo for the missiles, however, there is currently no way of knowing how many missiles you currently have. Today we are going to make a new UI element.
To begin, we right click on the canvas in the hierarchy and create new, UI, text.
Change the name of the text object and drag it into place.
Set the type size and color.
Don’t forget to anchor into place.
Once it looks right we can open the UI manager script and now we need to make a text variable for our element as well as two int variables for current and max ammo.
In the start method we want to set the text element to display what the max missile ammo is and the current missile ammo is.
We need to update the current missile variable every time the missile is launched. We create a method to handle the subtraction.
On the player script we need to call this method every time we call the missile ammo update method.
With this the current missile displayed to the player will update every time the player launches a new missile.
We are almost done with the player missiles. In the next tutorial we are going to finish with creating a powerup. The powerup will give the player more missile ammo. As I always say, don’t be afraid to experiment with your code, and I’ll see you in the next tutorial!