Adding Currency on game Start

Niroan

Member
How do i add currency on game start?
I get all my currency from Cloud and i would like to keep track of them one place.


So i want to inject the value in game start into UIS.

C#:
//Get the dollar currency from the database.

var dollars = InventorySystemManager.GetCurrency("Dollars");


//create a variable holding 50$.

var fiftyDollars1 = new CurrencyAmount(50, dollars);


//You can use this shortcut if you find it easier to read.

var fiftyDollars2 = (50, dollars);
 
The currency of your player is defined by a Currency Owner component, it should be added on the same gameobject as your player inventory:
1601882954757.png

You can add/remove currency to/from the currency owner. The CurrencyAmounts property has more options for adding and removing currency.

C#:
            //Get the currency by name or you can get it by reference as a serialized field.
            var dollars = InventorySystemManager.GetCurrency("Dollars");

            //The simplest way.
            currencyOwner.AddCurrency(dollars, 10);
            
            //For more options use the currencyAmounts property.
            currencyOwner.CurrencyAmount.AddCurrency(dollars, 10);
 
Top