VOOZH about

URL: https://www.geeksforgeeks.org/c-sharp/score-system-in-unity/

⇱ Score System In Unity - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Score System In Unity

Last Updated : 4 May, 2026

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.

Output:

👁 Score-Manager-In-Unity
Score Manager In Unity

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.

Output:

👁 Adding-Score-When-Enemy-Die-In-Unity
Adding Score When Enemy Die In Unity

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.

Output:

👁 Displaying-Score-In-Unity
Displaying Score In Unity

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.

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.

PlayerPrefs.GetInt() loads saved data. PlayerPrefs.SetInt() saves new high score. The data stays on player's device even after game closes.

Complete Flow

  1. Player kills enemy then enemy calls AddScore()
  2. ScoreManager increases score
  3. ScoreDisplay updates UI text
  4. If score beats high score - Save new high score
Comment
Article Tags:
Article Tags:

Explore