- Home /
Changing Variable OnMouseClick? Help!
Hey everyone. I'm trying to attach the following script to a box to allow me to set a maximum number of items inside, and what I want is for that number to decrease by one each time I click it. This has been stumping me for quite a while and if someone can help me correct my code I'd really appreciate it. I'm a beginner and I'm sure its something simple, but please explain where I went wrong in simple terms as I'm not familiar with ALL of the scripting jargon yet. :-) Thanks a lot in advance.
var maxCount : int = 10;
var presentCount : int = 10;
function OnMouseClick(){
presentCount -= 1;
}
function Update(){
if (presentCount <= 0)
{
Destroy(gameObject);
}
}
Answer by DaveA · Apr 28, 2011 at 09:35 PM
Where is OnMouseClick called? Did you mean OnMouseDown? Does your object also have a Collider component attached? If not, OnMouseDown never gets called.
Wow, that was it. Something so simple. Thanks a lot Dave! I'm still learning the API and the general functions so I'm fleshing out these smaller things first in an attempt to do it.
Ok then. Since you're new, you should know that when you like an answer, hit the 'checkmark' there to the left to 'accept it' to let people know it's been answered.