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);
}
}