Int Value not being calculated correctly?

Hi, so I’m trying to create an in-game economy, and I’ve created two scripts that will add and subtract money.

The money is added (with a value of 1000) on the left mouse click, and money is subtracted (with a value of 1000) with the right mouse button. Except when I click it will sometimes add or subtract 1000, 2000 or 3000 even though there is only one mouse press.
Script one
public void addMoney(int moneyToAdd)
{
money += moneyToAdd;
}
public void subtractMoney(int moneyToSubtract)
{
if (money - moneyToSubtract < -15000)
Debug.Log(“Not enough money”);
else
{
money -= moneyToSubtract;

Script two (references script one)
void Update () {
if (Input.GetButton(“Fire1”))
{
cam.GetComponent().addMoney(1000);
}
if (Input.GetButton(“Fire2”))
{
cam.GetComponent().subtractMoney(1000);
}
}

Use code tags, and what’s your problem ?

Change Input.GetButton to Input.GetButtonDown and that should solve your problem.
GetButtonDown is only called once and GetButton is called many times, while you keep the button pressed.

Input.GetButtonGets called ones per frame, and will return true as long as the button is pressed. Change that to

Input.GetButtonDown
// or
Input.GetButtonUp

and your problem will go away.

Also, next time please use Code Tags when posting code.

I had that code in originally (GetComponentUp/Down) and that had the same issue.