- Home /
On Click, increment variable
Hi Everyone, I'm starting to pull my hair out over this. I started a new project after taking a break from coding for a while and I can't seem to do something which should be very simple.
I'm trying to increase a variable by one each time I click on a specific object. This is the code I have attached to the object:
var timesClicked = float;
function OnMouseDown() {
timesClicked ++;
}
All I'm trying to do is track how many times an object has been clicked. I keep getting an error stating
"BCE0051: Operator '+' cannot be used with a left hand side of type 'System.Type' and a right hand side of type 'int'.
I'm not using an int though, I'm using a float, and I'm certain this has worked before.
This shouldn't be so difficult. There must be something stupid I'm overlooking.
Answer by Sharon Hanlon · Feb 18, 2012 at 08:45 PM
var timesClicked = float; is incorrect. Try this instead: var timesClicked:float = 0.0;
I feel so stupid. Your suggestion is right. Thank you!
Your answer
Follow this Question
Related Questions
Buttons around game object. UGUI 4.6 0 Answers
Programmatically call OnMouseDown() of a GameObject [solved] 1 Answer
Pause button not getting clicked 0 Answers
How to make a variable fall/rise over time? 1 Answer
Variable from Inputfield is being updated but when I go to use it, its empty sting 1 Answer