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.

1 Answer

1

var timesClicked = float; is incorrect. Try this instead:
var timesClicked:float = 0.0;

I feel so stupid. Your suggestion is right. Thank you!