So having objects in the game and creating interactions is great an all, but how do we let our player know things like their score? We can do this easily with UI! First thing is we need to create our UI Element. Being a score that will be text.
Double click the canvas to get a full view of the UI. Name your element however you want I just did score and in the Text field put what you want to display such as Score. It’s easy to move and change the color of the font as well.
You will also want to set an anchor point. This helps with scaling which also on the Canvas object you will want to change the scale mode to scale with screen size. That way if the size of your screen changes the size of the UI and position will not.
Now that we have our element created we need to access it and actually add our score to it. First we actually need a score variable to begin with. So inside our player lets create that. We can serialize this in order to test it in the editor easily.
Now we need a method to actually tell our game to add this score up.
All we need now is to tell our player to activate this method. Well given our enemy is the target we can put this code there and create the communication to the player.
If this was done correctly we will see the score update on the player script in the inspector after we damage and enemy like so.