
Unity UI Cookbook
By :

In this recipe, we are going to create a score counter that displays the score as a number on the screen. To achieve this, we will use the Text (Script) component and create a script to handle it. Different functions will be available from this script, that will be called from other scripts to increase the score.
First of all, we need to create new UI text to display our score. Thus, right-click on the Hierarchy panel and then UI | Text. Finally, rename it to ScoreCounter.
To rename an object, right-click on it and select Rename. Otherwise, we can change its name in the Inspector window.
Next, we can change the Font and the Font Size in the Inspector as we wish, to better suit our needs.
Furthermore, we should also adjust the Color. In this example, we will set it to white in order to be easily visible within the scene.
Now, we need to drag the ScoreCounter with the Rect Tool (the hotkey for this tool is T, and we have seen it in the previous chapter...
Change the font size
Change margin width
Change background colour