private void OnTriggerEnter2D(Collider2D collision) { /*If we collide with an item then we want to add it to the Inventory*/ if (collision.gameObject.tag == "Item") { string ItemName = collision.gameObject.name; ItemBase Item = new ItemBase(); ItemManager.items.TryGetValue(ItemName, out Item); Sprite ItemSprite = collision.GetComponent <SpriteRenderer>().sprite; if (cInventory.HasItem(Item.GetName()) && Item.GetStackable() == true) { Item.AddAmount(1); cInventory.UpdateUI(); } else { //Item.SetAmount(1); //Item.SetSpriteImage(ItemSprite); cInventory.AddItem(Item); cInventory.UpdateUI(); } Debug.Log("COLLISION!"); } // if we collide with a bed then show the sleep menu and pause the game if (collision.gameObject.tag == "Bed") { SleepUI.SetActive(true); PauseMenuScript.GameIsPaused = true; //cClock.NightUpdate(); //Debug.Log("COLLISION!"); } // if we collide with the sell chest then enable it if (collision.gameObject.tag == "SellChest") { cChest.DisabledNEnable(); if (!cInventory.ImageParent.gameObject.activeInHierarchy) { cInventory.DisabledNEnable(); } } // if we collide with the shop then enable the shop if (collision.gameObject.tag == "SeedShop") { SeedShopUI.SetActive(true); } if (collision.gameObject.tag == "ToolShop") { ToolShopUI.SetActive(true); } }
/*RIP AZIR*/ public void BuyShopItem() { XMLParser XML = GameObject.FindGameObjectWithTag("ItemManager").GetComponent <XMLParser>(); MoneyClass PlayerMoney = GameObject.FindGameObjectWithTag("Player").GetComponent <MoneyClass>(); InventoryClass cInventory = GameObject.FindGameObjectWithTag("InventoryManager").GetComponent <InventoryClass>(); ItemBase Item = new ItemBase(); ItemBase NewItem = gameObject.GetComponentInParent <ItemBase>(); ItemTypeFinder TypeFinder = GameObject.FindGameObjectWithTag("ItemManager").GetComponent <ItemTypeFinder>(); // Get the object the component will be on and give it a name GameObject SubGameObject = new GameObject(NewItem.bName); SubGameObject.transform.parent = cInventory.ToolItems.transform; // If the player has enough gold if (PlayerMoney.GetMoney() >= NewItem.GetSellPrice()) { // If it has the item and is stackable if (cInventory.HasItem(NewItem.GetName()) && NewItem.GetStackable()) { cInventory.AddAmount(NewItem.GetName(), NewItem.GetAmount()); PlayerMoney.SetMoney(PlayerMoney.GetMoney() - NewItem.GetSellPrice()); } else { // Find the type of the item and set it up, after add it to the dictionary. Item = TypeFinder.ItemTyepFinder(NewItem, SubGameObject); Item.SetUpThisItem(NewItem.bItemType, NewItem.bName, NewItem.bAmount, NewItem.bStackable, NewItem.bSrcImage, NewItem.bSoundEffect, NewItem.bTile, NewItem.bPrefab, NewItem.bSellPrice, NewItem.bCustomData, NewItem.GetDesc()); cInventory.AddItem(Item); PlayerMoney.SetMoney(PlayerMoney.GetMoney() - Item.GetSellPrice()); } } cInventory.UpdateUI(); }