Variable doubling after clicking an object.

I’m creating a small idle game like cookie clicker. I’ve only just added the main button to click and earn points but instead of adding 1 point it adds 2. I think it’s the refresh rate of the scene but I was wondering how I could fix it.

`
void OnMouseOver()
{
if (Input.GetMouseButtonDown(0)
{
totalClicks++;
}
}

void Update()
{
OnMouseOver();
}
`
All I’m doing is increasing the totalClicks and printing it out with a text ui but for some reason it adds 2 points instead of 1. Thanks for the help.

Did you check what OnMouseOver does?

Called every frame while the mouse is over the GUIElement or Collider.

Update is called every frame as is OnMouseOver if you hover, and both of them increment the variable if the mouse button is pressed => it gets incremented twice.

Maybe just use OnMouseDown?