Hi,
I have an inventory system in my game.
Currently there are only 2 items(Angel wing piece and angel wing).
I want to do a simple thing: When i have 2 angel wing pieces in my inventory,i want them them removed from the inventory and replaced by an angel wing.
I wrote the code but it seemed a little complicated.
public void InventoryUpdate() { GetUserInventoryRequest request = new GetUserInventoryRequest(); PlayFabClientAPI.GetUserInventory(request, result => { List<ItemInstance> ii = result.Inventory; int slotid = 0; int AngelPieces = 0; for (int i = 0; i < 6; i++) { Slots[i].Unassign(); } foreach (ItemInstance i in ii) { if (i.ItemId == "Angel Wing Piece") { AngelInstanceId[AngelPieces] = i.ItemInstanceId; AngelPieces++; } if (i.ItemId == "Angel Wing") { Slots[slotid].Assign(UIItemDatabase.Instance.GetByID(31)); slotid++; } } if (AngelPieces== 2) { for (int i = AngelPieces - 1; i >= 0; i--) { PlayFabClientAPI.ExecuteCloudScript(new ExecuteCloudScriptRequest() { FunctionName = "DeleteItems", FunctionParameter = new { InvItemId = AngelInstanceId[i] }, GeneratePlayStreamEvent = true, }, result3 => Debug.Log(""), error => Debug.Log("")); } PlayFabClientAPI.ExecuteCloudScript(new ExecuteCloudScriptRequest() { FunctionName = "GrantItem", FunctionParameter = new { catalogVer="Items",ItemId="Angel Wing"}, GeneratePlayStreamEvent = true, }, result3 => Debug.Log(""), error => Debug.Log("")); Slots[slotid].Assign(UIItemDatabase.Instance.GetByID(31)); slotid++; } else if (AngelPieces == 1) { Slots[slotid].Assign(UIItemDatabase.Instance.GetByID(28)); slotid++; } }, error =>{}); }
*Is there a simpler way to do this?