question

recino-studio avatar image
recino-studio asked

How can I update the value of the virtual currency?

Here I get the value, but I want to update it. What is the function for it?

    void GetCurrencySuccess(GetUserInventoryResult result)
    {
        int currencyValueGetted;
        result.VirtualCurrency.TryGetValue(CURRENCYID, out currencyValueGetted);
        currency = currencyValueGetted;
        currencyDisplay.text =  currency.ToString();
        inventory.coins = currency;
    }

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Made Wang avatar image
Made Wang answered

GetUserInventory is an api that can help you get the user's virtual currency and the items in the inventory.

If you want to update the value of virtual currency, first you need to determine whether you are developing a client or a server.

If it is a client, you can use the client api AddUserVirtualCurrency and SubtractUserVirtualCurrency, but these two client apis are disabled by default. You need to select Allow client to add virtual currency and Allow client to subtract virtual currency in the GameManager. But it is not safe, so we recommend that you call the server api AddUserVirtualCurrency and SubtractUserVirtualCurrency on CloudScript.

If you are developing a server, you can directly call the server api AddUserVirtualCurrency and SubtractUserVirtualCurrency.

If you need some samples, maybe you need to tell me your development platform.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.