Trying to get score counter...

I got my score counter to show up on my GUI Text, yet when I switch to another object with the same script its resets the score to zero. What can i change or add to stop it from resetting?

var speed = 5;
var buck = 100;
var deer = 10;
private var score : int = 0;
var ScoreBoard: GUIText;


function Update () {
	transform.position += Vector3.forward * Time.deltaTime * speed;
}

function OnMouseEnter () {
	Debug.Log("Hit");
	speed = 15;
	deer += 10;
	ScoreBoard.text = ("Score: ") + deer;
}	

function OnMouseExit () {
	Debug.Log("Safe");
	speed = 5;
}

Wait. Are you attaching the same script to multiple objects? Because if you’re doing that, this will treat each ‘val deer’ as different ones.

You’d need to setup a control script that acts as a global counter. This controller script can handle things like score keeping.

You can declare score as a static variable:

static var score : int = 0;

A static variable is created once at the program beginning, lives while the program is running and is unique: all script instances use the same variable. Non-static variables exist in each script instance and are independent of each other.