question

robertcaramidarusky avatar image
robertcaramidarusky asked

Assets\MigrationScript.cs(123,32): error CS0246: The type or namespace name 'GrantItemsToUserResult' could not be found (are you missing a using directive or an assembly reference?)

using System.Collections; using System.Collections.Generic; using UnityEngine; using PlayFab; using PlayFab.ClientModels;

public class MigrationScript : MonoBehaviour { public GetPlayerIdOnStart GetPlayerIdOnStart;

 void GrantItem(string itemId, string catalogVersion)
 {
     var request = new GrantItemsToUserRequest
     {
         PlayFabId = GetPlayerIdOnStart.MyPlayfabID,
         ItemIds = new List<string> { itemId },
         CatalogVersion = catalogVersion
     };
     PlayFabClientAPI.GrantItemsToUser(request, OnItemGranted, OnError);
 }

 public void AddLandsMonny(int lands)
 {
     var request = new AddUserVirtualCurrencyRequest
     {
         Amount = lands,
         VirtualCurrency = "LS"
     };
     PlayFabClientAPI.AddUserVirtualCurrency(request, OnCurrencyAdded, OnError);
 }

 void Migrate()
 {
     //the code
 }

 private void OnItemGranted(GrantItemsToUserResult result)
 {
     Debug.Log(result);
 }

 void OnCurrencyAdded(ModifyUserVirtualCurrencyResult result)
 {
     Debug.Log(result);
 }

 private void OnError(PlayFabError error)
 {
     Debug.LogError(error);
 }

}

sdks
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

·
Xiao Zha avatar image
Xiao Zha answered

Since PlayFab only provides Server API: GrantItemsToUser and Admin API: GrantItemsToUser, there is no GrantItemsToUser API in the PlayFab Client APIs which causes this error. Based on your code, it looks like you want to implement the functionality of granting items and adding currency to players, we don't recommend doing this on the client side due to the risk of players cheating. We recommend implementing these two functions in AzureFunction. If you really need to grant item to players on the client side, please read the risks mentioned in #if ENABLE_PLAYFABSERVER_API - Playfab Community and follow it to enable the Server API on the client side.

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.