Adding a float to another float not working

I am currently making a bitcoin miner idle game. In the game you are able to transfer the bitcoin in your miner to your wallet. The issue is when it adds the bitcoin in the miner to the wallet it sets the bitcoin in the miner to 0 (which is what I want) but it doesn’t add the bitcoin in the miner to the wallet. The bitcoin in the wallet still stays zero. Help please!

public void TransferToWallet()
    {
        if (Mine.Instance.btcAmount == 0)
            return;

        Mine.Instance.btcAmount += btcInWallet;

        Debug.Log("Transferred" + Mine.Instance.btcAmount);

        Mine.Instance.btcAmount = 0;

        Mine.Instance.btcText.text = Mine.Instance.btcAmount.ToString("f6");
  
    }

(Mine.Instance is a singleton)

You’re literally setting it zero on line 10…

Mine.Instance.btcAmount = 0;

I’m setting it to 0 on the bitcoin miner. Not the wallet. Even without that line of code it doesn’t work. I’m pretty sure the issue has something to do with line 6. Or maybe I’m just being dumb, I dunno.

I think you have your addition the wrong way around:

Mine.Instance.btcAmount += btcInWallet;

Unless I am mistaken, this looks like it is adding the value in btcInWallet to btcAmount (which is then zeroed out a couple of lines later).
You probably want:

btcInWallet += Mine.Instance.btcAmount;

To actually add the btcAmount onto the wallet?

1 Like

This worked! I didn’t even realize that it was the wrong way around until now LMAO. Thank you so much!