A score system in Unity is used to track and display the player’s points based on in‑game actions such as collecting items, defeating enemies, or completing objectives. It helps enhance gameplay by providing feedback and motivating player progression.
Basic Score Manager
ScoreManager is a script that stores the current score and provides a method to increase it.
using UnityEngine;
public class ScoreManager : MonoBehaviour
{
public int score = 0;
public void AddScore(int amount)
{
score += amount;
}
}
Output:

Create an empty GameObject in your scene, attach this script, and name it "ScoreManager". The AddScore() method can be called from any other script.
Adding Score When Enemy Dies
When an enemy dies, it should tell the ScoreManager to add points.
public class Enemy : MonoBehaviour
{
public int scoreValue = 10;
void Die()
{
ScoreManager sm = FindObjectOfType<ScoreManager>();
sm.AddScore(scoreValue);
Destroy(gameObject);
}
}
Output:

FindObjectOfType<ScoreManager>() finds your ScoreManager in the scene. Different enemies can have different scoreValue (10 for small, 50 for boss).
Displaying Score on Screen
Create a UI Text to show the score to the player.
using TMPro;
using UnityEngine;
public class ScoreDisplay : MonoBehaviour
{
public ScoreManager sm;
public TextMeshProUGUI scoreText;
void Update()
{
scoreText.text = "Score: " + sm.score;
}
}
Output:

Drag the ScoreManager GameObject and the UI Text into the script's slots in Inspector. The text updates every frame to show current score.
Collectible Items (Coin)
Coins or gems should add score when the player touches them.
public class Coin : MonoBehaviour
{
public int scoreValue = 5;
void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
{
ScoreManager sm = FindObjectOfType<ScoreManager>();
sm.AddScore(scoreValue);
Destroy(gameObject);
}
}
}
The coin has a trigger Collider. When player enters, score increases and coin disappears.
Saving High Score
High score should save even after closing the game. PlayerPrefs does this.
public class HighScore : MonoBehaviour
{
void Start()
{
// Load saved high score (0 if first time)
int saved = PlayerPrefs.GetInt("HighScore", 0);
}
public void SaveScore(int currentScore)
{
if (currentScore > PlayerPrefs.GetInt("HighScore", 0))
{
PlayerPrefs.SetInt("HighScore", currentScore);
}
}
}
PlayerPrefs.GetInt() loads saved data. PlayerPrefs.SetInt() saves new high score. The data stays on player's device even after game closes.
Complete Flow
- Player kills enemy then enemy calls AddScore()
- ScoreManager increases score
- ScoreDisplay updates UI text
- If score beats high score - Save new high score