How can i get a scoring system?

Hi.

I’m making my first game and its almost done. it just needs a scoring system. I have spent hours trying to find a tutorial but i just can’t get it to work.

My goal is to make it so every time i kill an enemy (using prefabs) i would score a point and it would add 1 to the counter that is on the screen.

Thank you in advance.

ps. I’m using C#

You didn’t provide much information about your game or some code so here’s a dirty example :

  1. Test Scene setup Attach
  2. ScoreManager.cs to a new GameObject
  3. Attach EnemyScript.cs to a cube
  4. Press Play Click 10 times with left mouse

Enemy gameObject should be Destroyed and Score should be set to 1

ScoreManager.cs

using UnityEngine;

public class ScoreManager : MonoBehaviour {

	public static int Score;
	public int _score { 
		get 
		{ 
			return Score; 
		} 
		set
		{
			Score = value;
		}
	}
	
	void OnGUI(){
		GUILayout.Label ("Score : " + _score.ToString());
	}
}

EnemyScript.cs

using UnityEngine;

public class EnemyScript : MonoBehaviour {
	
	static int Health = 10;
	
	void Update () {
		if (Input.GetMouseButtonDown (0)) {
			Health -= 1;
		}

		if(Health <= 0){
			ScoreManager.Score += 1;
			Destroy(gameObject);
		}
	}
}