unity c# money system

I want this to program please help me im stock with this logic!
example:
i have a $10 dollar money and when playing the game i get score of $4 how can i add the $4 in the $10 money. How can i code that in unity c#

Hey Margallo,

An exact implementation for a money system will depend on the nature of your game. A simple way of doing this is to store your “money” as an int and to increase/decrease it as needed.

For example:

// Simple money system

public int playerMoney = 0; // Start with $0

// Function to increase money
// This should change based on the way you want to
// have the player make money

void addPlayerMoney(addAmount){
    playerMoney += addAmount;
}

So now whenever addPlayerMoney() is called, it’ll increased your money variable by addAmount.
From here, it’ll be up to you! For example, calling addPlayerMoney(5) will increase your money by 5, and playerMoney will now = 5.

I hope this helps!

I’m sorry for my bad english @ dacarrera! that’s why its not working the totalMoney and the money is reverse thanks :slight_smile: but one more thing how can i save the totalMoney using playerprefs?