boolean flag problem

Hello,

I make a game where the player is supposed to click thing to get points, but only one click per object. I tried this code, but it doesn’t work, and the player keeps getting points if clicks on the same object.

Any help?

function OnMouseDown () {
	var hitted : boolean;
	if(!hitted)
	{
		var score : ScoreCounter = GameObject.Find("Score").GetComponent("ScoreCounter");
		score.scorePoints ++;
		hitted = true;
	}
}

you have to have your

hitted

variable outside of the function. The way it is now, you allways declare new hitted variable. You do not have any reference to past events.

var hitted : boolean;

function …