question

Noah Branham avatar image
Noah Branham asked

How could I display virtual currency value in Unity C#?

Hey! So my code is as follows:

GetUserInventoryRequest requestInventory = new GetUserInventoryRequest();

PlayFabClientAPI.GetUserInventory(requestInventory, result =>

{

//GoldAmtText.text = result.VirtualCurrency.Keys.ToString();

}, error =>

{

Debug.Log(error.ErrorMessage);

});

I was able to get the display name and do it in a similar way. Could you point me in the right track of how to get a virtual currency's value? Like I know that there are multiple virtual currencies, the one I'm trying to get the value of is GO or "Gold", how would I access that single currency and get the amount?

apisCharacter Data
10 |1200

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

v-humcin avatar image
v-humcin answered

This is a small example of one way to access currencies:

result.VirtualCurrency.TryGetValue("GO", out gold);

The important thing to note is that VirtualCurrency is a Dictionary with "string" keys and "int" values, so you have to use a specific key to get a value. TryGetValue() allows you to check if a key exists and then output the value into a integer variable. After which you could set the text to the ToString() of the int variable. In your case you would use "GO" as the key.

1 comment
10 |1200

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

Noah Branham avatar image Noah Branham commented ·

Thank you so much! Never used playfab and I appreciate the clarification!

0 Likes 0 ·
Noah Branham avatar image
Noah Branham answered

I don't know how to reply to your answer on mobile, but thank you so much! Never used playfab before so was a tad bit confused. Thanks for clarifying!

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.