How to Add Scores to a Game in Unity 2D

  1. Create a text object by right-clicking in a blank area in the Hierarchy section, then choosing UI > Text, from the pop-up menu.

2. Create a C# Script (MonoBehaviour) and change name to ScoreScript.cs. This script will be responsible for displaying the new score value. See example below:

##############################

###############################

3. Save the script and drag the new script to your ScoreText Game Object as shown below:

4. On another script that is calculating the score, you will need to use the onTrigger() function to provide an updated value for score. In the example script below, if a Game Object such as a “coin” is touched by the Player, the player’s score increases by 10 points.

5. In the game example below, the player is the Shark and whenever the Shark eats a Tuna, the player’s score increases by 10 points for each Tuna fish it eats.