예제 #1
0
파일: Open.cs 프로젝트: horoxix/lootbox
 // On click to OpenBox, looks at how many items are in the box and adds an Item.
 public void OpenBox()
 {
     if (User.user.LootBoxes > 0)
     {
         LootBox lootBox = GenerateLootBox();
         if (User.user.inventory.Count + lootBox.ItemCount > User.user.InventorySlots)
         {
             errorText.enabled = true;
             errorText.text    = "Your inventory is too full!";
             StartCoroutine(DisableErrorText());
             return;
         }
         for (int i = 0; i < lootBox.ItemCount; i++)
         {
             GameObject thisObject = lootManager.lootSlots[i].gameObject;
             ClearItemSprites(thisObject);
             CreateLoot(thisObject, thisObject.GetComponent <Image>());
         }
         User.user.Experience += lootBox.Experience;
         if (User.user.Experience >= User.user.ExperienceToNext)
         {
             LevelUp levelUp = new LevelUp();
             levelUp.IncreaseLevel(playerLevelText, firebaseManager);
         }
         if (User.user.LootBoxes == User.user.MaxLootBoxes)
         {
             firebaseManager.UpdateLastTimeOpenedLootBox();
         }
         User.user.LootBoxes  -= 1;
         User.user.Experience += lootBox.Experience;
         firebaseManager.UpdateDatabaseValues();
     }
     else
     {
         errorText.enabled = true;
         errorText.text    = "You do not have any more loot boxes!";
         StartCoroutine(DisableErrorText());
     }
     //DataManager.dataManager.Save();
 }