- 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:
##############################
using UnityEngine;
using UnityEngine.UI;
public class ScoreScript : MonoBehaviour
{
public static int scoreValue = 0;
Text score;
void Start()
{
score = GetComponent<Text>();
}
void Update()
{
score.text = “Score: ” + scoreValue;
}
}
###############################
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.
using UnityEngine;
public class Coins : MonoBehaviour
{
private GameObject player;
void Start()
{
player = GameObject.FindGameObjectWithTag(“Player”);
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.tag == “Border”)
{
Destroy(this.gameObject);
}
else if (collision.tag == “Player”)
{
//adds 10 points to scoreValue in ScoreScript.cs then destroys the “coin” from the screen
ScoreScript.scoreValue += 10;
Destroy(this.gameObject);
}
}
}
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.