On point!
Points can come in various ways. A player can obtain points by defeating an enemy, doing the right thing, or even working cooperatively with other players. Now we have worked on a lot of images, this section shows us how to use the text component to implement a Point System.
Let's start by creating a text component. To do this, right-click on the Hierarchy panel and then select UI | Text. We can rename it Point System
. Feel free to customize it as you want by changing the font, size, and so on. It doesn't matter what text you put in it, because it will be replaced by our script, but we can use anything as a placeholder. In this case, we can write Points: 100
. Once we have done all of this, we should have something that looks the following screenshot, in the Scene view:
The points system in Unity
Now, let's add a script and name it PointSystemScript
. Since we are going to use UI components, let's import the library by adding the following line at the beginning of our script:
using...