💰 How to Add a New Currency

This guide explains how to create and integrate a new in-game currency using the CurrencyData system provided by the template.

🧾 Step-by-Step Instructions

1. Create the Currency Asset

  • Right-click in the Project windowCreatePetCareGameCurrency Data

  • Set the following fields:

    • coinName: Display name (used in UI only)

    • coinID: Unique identifier (e.g. "gems", "stars")

    • icon: Sprite shown in UI

    • initialAmount: Starting value for new players

    • (Optional) Configure limits and recharge options as needed

⚠️ coinID must be unique across all currencies


2. Add to the GameInstance

  • Open the GameInstance Component in Home Scene

  • Locate the currencyData array

  • Add your new CurrencyData asset to this list

public CurrencyData[] currencyData;

This allows the system to initialize and track your new currency globally.


3. Display Currency in the UI

To show the value of your currency in the interface:

  • Add a CurrencyDisplay component to a UI element (e.g. under your HUD)

  • Set the currencyID to match your new coin

  • Assign the TextMeshProUGUI and Image references

currencyDisplay.currencyID = "gems";

If your currency is rechargeable, enable the toggle and link the recharge UI fields.


4. Modify Currency Values

You can use the following functions to manipulate player currency:

// Add coins
PlayerSave.AddCoin("gems", 10);

// Remove coins
PlayerSave.RemoveCoin("gems", 5);

// Get current amount
int current = PlayerSave.GetCoin("gems");

⚡ Rechargeable Currencies

If isRechargeableCurrency is enabled:

  • The system will automatically recharge the coin every X seconds/minutes/hours

  • Recharge logic is handled by RechargeablesManager and UI updated by CurrencyDisplay

You can also specify:

  • Offline recharge support

  • Max limit enforcement

  • Can exceed max toggle for gifts or purchases


✅ Summary

Feature
Supported

Multiple currencies

Recharge over time

Per-currency icon

UI auto-display

Offline recharge

Max limits per currency

This system is fully modular and supports coins, gems, stamina, energy, and other economy models.

Last updated