Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Check if Inventory are empty

Discussion in 'Scripting' started by bigdog16, May 1, 2020.

  1. bigdog16

    bigdog16

    Joined:
    Mar 5, 2018
    Posts:
    12
    Hello, I would like to check at Playfab whether the player's inventory is empty. But unfortunately it doesn't work for me. Can someone help me please


    Code (CSharp):
    1.  
    2.         GetUserInventoryRequest getUserInventoryRequest = new GetUserInventoryRequest();
    3.         PlayFabClientAPI.GetUserInventory(getUserInventoryRequest, OnGetUserInventory, OnPlayFabError);
    4.     }
    5.  
    6.     private void OnPlayFabError(PlayFabError obj)
    7.     {
    8.         throw new NotImplementedException();
    9.     }
    10.  
    11.     private void OnGetUserInventory(GetUserInventoryResult result)
    12.         {
    13.  
    14.         List<ItemInstance> userInventoryList = result.Inventory;
    15.  
    16.         foreach (ItemInstance i in result.Inventory)
    17.         {
    18.            
    19.          
    20.  
    21.                    if(userInventoryList.Count == 0)
    22.                      {
    23.                 SceneManager.LoadScene("IntoChoose");
    24.                 break;
    25.  
    26.             }
    27.         }
    28.             }
    29.  
     
  2. sbalanoff

    sbalanoff

    Joined:
    Nov 14, 2019
    Posts:
    36
    Code (CSharp):
    1. public bool checkIfEmpty(List<GameObject> list){
    2.     if(list.Count == 0){
    3.         return true;
    4.     } else {
    5.         return false;
    6.     }
    7. }
     
    bigdog16 likes this.
  3. bigdog16

    bigdog16

    Joined:
    Mar 5, 2018
    Posts:
    12
    thank you :)
     
    Last edited: May 2, 2020
    sbalanoff likes this.