public void TakeObject(GameObject toCollect) { if (!toCollect.name.Contains("coin")) { for (int i = 0; i < collectableGameObjects.Length; i++) { if (toCollect == collectableGameObjects[i]) { addUIObjImg.sprite = toCollect.GetComponent <InventoryObjects>().inventorySprite; addUIObjTxt.text = loadXmlScript.MiscClass.newObject; addUIObjImg.gameObject.SetActive(true); addUIObjTxt.gameObject.SetActive(true); InventoryArrowBehaviour.Sprites.Add(toCollect.GetComponent <InventoryObjects>().inventorySprite); inventoryDescriptionScript.Collection.Add(toCollect.GetComponent <InventoryObjects>()); print("To collect " + toCollect.name); Destroy(toCollect); } } InventoryArrowBehaviour.ReorderInventory(); } else { goldText.SetActive(true); goldImage.SetActive(true); goldAmount.text = (int.Parse(goldAmount.text) + 4).ToString(); Destroy(toCollect); } }
public void Accept() { //COMPROBAMOS QUE EL DINERO TOTAL NO SEA MENOR QUE EL PRECIO DEL OBJETO if (int.Parse(totalGold.text) >= invObj.price) { totalGold.text = (int.Parse(totalGold.text) - invObj.price).ToString(); int i = 0; //DESTRUIMOS EL OBJETO COMPRADO. LO BUSCAMOS EN EL ARRAY Y LO DESTRUIMOS while (i < goods.transform.childCount) { if (invObj.shopSprite == goods.transform.GetChild(i).GetComponent <Image>().sprite) { Destroy(goods.transform.GetChild(i).gameObject); i = goods.transform.childCount; } i++; } //ACTUALIZAMOS LA CANTIDAD DE DINERO Y CERRAMOS EL PANEL DE COMPRA goldAmountShop.text = totalGold.text; transform.parent.gameObject.SetActive(false); blur.SetActive(false); //LE PASAMOS EL OBJETO A LA DESCRIPCION inventoryDescriptionScript.Collection.Add(invObj); //LE PASAMOS EL OBJETO A LOS SPRITES DEL INVENTARIO inventoryArrowBehaviour.Sprites.Add(invObj.inventorySprite); inventoryArrowBehaviour.ReorderInventory(); description.text = ""; } else { noCoin.SetActive(true); } }