in this lecture, we are going to create the coin label UI 2 2
let's right-click on the GameScreen node and select Add Child Node, then search and add a Label node 3 3
rename the Label node to CoinLabel 4 4
let's put 0 in the Text field for testing 5 5
then let's create a new LabelSettings for the Label Settings property 6 6
then let's click the new LabelSettings again to expand the settings 7 7
expand Font and set the size to 80 8 8
then set the color of the font to ffca00 9 9
next, let's scroll down to set the Layer Mode to Anchors and the Anchors Preset to Top Right 10 10
then let's set Position to 1066 / 20 so there is some space between the coin label and the upper-right corner of the screen 11 11
all right, let's check out how the coin label looks 12 12
great, the coin label is in the upper-right corner of the screen 13 13
next, let's declare a signal in the Player script, let's call it playerCoinUpdated() with a parameter called newValue 14 14
also let's declare a variable called currentCoin to hold onto how many coins the player has, the define value is 0 15 15
then let's use a setter to make sure whenever this variable changes, the playerCoinUpdated() signal also emits 16 16
and the parameter with the signal is currentCoin, so the Coin Label UI can update the number on screen 17 17
now let's go back to the CollectedCoin() function, delete the print() line and add the value to the currentCoin 18 18
then let's do something fun: let's restore the player's health just a little bit every time it collects a coin 19 19
so let's check if the player's currentHealth is less than its MAX_HEALTH 20 20
then let's restore the currentHealth by three times of the value of the coin 21 21
don't forget we need to check if currentHealth is greater that MAX_HEALTH afterwards, and clamp currentHealth if needed 22 22
all right, let's go back to the UI_Manager script and bring in the CoinLabel node 23 23
then let's create a function called UpdateCoinLabel() at the bottom, with an int parameter called newValue 24 24
we need this parameter to match the playerCoinUpdated() signal in the Player script 25 25
in the function, we just need to update the number in the lable by setting the text property of the CoinLabel node to the newValue 26 26
but the text property only accepts a string type, so we use the str() function to convert the int type into the string type 27 27
the last thing is go connect the UpdateCoinLabel() function to the playerCoinUpdated() signal in the Player script 28 28
we are done with the scripts, let's switch to the 2D mode to place more coins in the level 29 29
select a Coin and press CTRL+D to duplicate it, and place it in somewhere else 30 30
then keep repeating the same step until you feel like you have enough coins to test 31 31
all right, let's press F5 to test our game 32 32
now the number in the upper-right increase as we collect the coins 33 33
let's also decrease the player's health to test the health restoring feature 34 34
great, the player's health increases a little bit by each coin collected 35 35
before we warp up this lecture, let's group all of the coins into one node to clean up the hierarchy 36 36
select all of the coin nodes, right-click and select Reparent to New Node 37 37
then just search and create a Node2D node 38 38
rename the Node2D node to Coins, that's it