Scoreboard/Leaderbord

Hi im making an singeplayer PFS zombie game and i want to show the player when they hit ‘tab’ they can see how many zombies he killed. I know what kind of things are neccessary but i don’t know how to put it in an code. In the script you need to know if the zombie is killed the score ++; you need an function OnGUI.label to show the player what score is…
can someone help me?

Here, this should work, it’s actually 2 scripts, one for the zombie, one for your main camera(a score management script). Somewhat untested, but I’ve used this method before, it works :wink: Let me know if you have any questions.

Here’s the zombie damage script (goes on all zombies)

//Zombie damage script
var hitPoints : float = 10.0 //insert zombie healthpoints here
var scoreManager : Transform; 

function Start()
{
	    scoreManager = GameObject.Find ("Insert Camera Name Here").transform; // this assigns the main camera (which should have the score management script attached to it) to the scoreManager variable.

}

function Update()
{
        if(hitPoints <= 0.0) //if zombie's hitpoints are less than 0.
	{
		Destroy(gameObject); // destroys the zombie
	    scoreManager.transform.GetComponent("Insert Score Management Script Name Here").AddScore1();//accesses the score management script and adds score.
	}
}

Now for the score manager script (this should be attached to your main camera).

//Score manager script
var score : int = 0;
var showScore : boolean = false;  //shows or hides the scoreboard
var tabToggle : boolean = false;  //shows whether or not the tab button has been pressed already

function Update()
{
        if(Input.GetKeyDown(KeyCode.Tab) && tabToggle == true) //if the tab button has not been pressed and we see the scoreboard
        {
                showScore = true;
                tabToggle = false;
        }
        if(Input.GetKeyDown(KeyCode.Tab) && tabToggle == false)//if the tab button has  been pressed and we do not see the scoreboard
        {
                showScore = false;
                tabToggle = true;
        }
}

function AddScore1() //when accesed by a dying zombie (from the damage script), adds to the total score.
{
	score += 1;
}

function OnGUI()
{
        if(showScore == true) //do we want to show the scoreboard right now?
	{
		GUILayout.Button("Zombies Destroyed: " + score); //prints the score to the GUI scoreboard
	}

}