question

popugamesconcept avatar image
popugamesconcept asked

Virtual Currency in Unity3D C#

I've been able to import the coins:

from Playfab to Unity Succes!

from Unity to Playfab Failed!

public int DragonCoins
	

 void Start()

   {
		AddInGameCurrency1 ();
		
   }

public void AddInGameCurrency1()
  {
    AddUserVirtualCurrencyRequest request = new AddUserVirtualCurrencyRequest();
    request.VirtualCurrency = "DC";
    request.Amount = DragonCoins;
    PlayFabClientAPI.AddUserVirtualCurrency(request, OnAddedInGameCurrency, OnAddGameCurrencyError);
  }



void OnAddedInGameCurrency(ModifyUserVirtualCurrencyResult result)
  {
    DragonCoins = result.Balance;
  }
  

 void OnAddGameCurrencyError(PlayFabError error)
 {
    Debug.LogError("Error adding in game currency: " + error.Error + " " + error.ErrorMessage);
 }
In-Game Economy
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

·
brendan avatar image
brendan answered

Sorry, are you saying you're experiencing an issue with this code? If so, can you please provide the Title ID and PlayFab ID used in the test, as well as the details of the error returned. Also, please confirm that you have enabled the Client AddUserVirtualCurrency API in your title's settings (which, by the way, we strongly advise against, as this provides hackers with a way to trivially add as much VC to their accounts as they want - which is why we have that API turned off for all titles by default).

2 comments
10 |1200

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

victorelselam avatar image victorelselam commented ·

@Brendan, so is there a way to add virtual currency by, for example, winning the game without using this API option?

0 Likes 0 ·
brendan avatar image brendan victorelselam commented ·

Our advice would be to process the game results in a Cloud Script or custom game server, and use the Server API version of the call. That way, you can have cheat prevention code in your server-authoritative logic.

0 Likes 0 ·

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.