- Home /
Question by
smirlianos · Oct 06, 2013 at 09:52 AM ·
mousebooleanonmouseupflag
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;
}
}
Comment
Best Answer
Answer by Lovrenc · Oct 06, 2013 at 09:56 AM
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 .....