question

pleasehelpme avatar image
pleasehelpme asked

How do I call a Currency or Catelog Item into Unity with SetText?

Hello, how do I call on the variable of a Currency or a Catalog Item into Unity as a SetText to display the number of "X Currency" and the number "Y Catalog Items" into a Text object?

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

·
akirachen avatar image
akirachen answered

For “the variable of a Currency”, API GetUserInventory can return you a list of users’ virtual currency balances in call back result.

For “ Catalog Item”, API GetCatalogItems can return you information of items in your specific catalog in call back result too.

Please refer https://api.playfab.com/docs/getting-started/unity-getting-started to learn how to make use of these API in Unity.

Unity http request code shown as below.

PlayFabClientAPI.GetUserInventory(new GetUserInventoryRequest { }, (result) =>
{
    int CurrenyBalance = result.VirtualCurrency["YourCurrencyName"];
}, OnGetError);
PlayFabClientAPI.GetCatalogItems(new GetCatalogItemsRequest { }, (result) =>
{
    foreach (var item in result.Catalog)
    {
        print(item.DisplayName + item.VirtualCurrencyPrices["YourCurrencyName"]);
    }
}, OnGetError);

Once the data comes back, combine them into a string and set your Text component’ text as your combined string. Code looks like below:

public GameObject yourTextGameObject;
yourTextGameObject.GetComponent<Text>().text= yourCombinedString;

If you have any other question or I misunderstood your question, please let us know.

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.