void Update() { if (actualizarTienda) { if (mostrarItems) { int childs = parentGrid.transform.childCount; for (int i = 0; i < childs; i++) { Destroy(parentGrid.transform.GetChild(i).gameObject); } ItemsBasicDAO itemsBasic = new ItemsBasicDAO(); List <ItemsBasic> lista = itemsBasic.GetItemsBasic().ToList(); for (int i = 0; i < lista.Count(); i++) { GameObject item = Instantiate(prefabItem) as GameObject; item.transform.name = lista [i].Name; item.GetComponent <BotonUsarPocion>().sePuedeUsar = false; item.GetComponent <BotonComprarItem>().sePuedeComprar = true; item.GetComponentInChildren <UILabel> ().text = lista [i].Name + " Precio: " + lista[i].Price; item.transform.parent = parentGrid.transform; item.transform.localScale = new Vector3(1, 1, 1); } } else { int childs = parentGrid.transform.childCount; for (int i = 0; i < childs; i++) { Destroy(parentGrid.transform.GetChild(i).gameObject); } EggBasicDAO eggBasic = new EggBasicDAO(); List <EggBasic> lista = eggBasic.GetEggBasicList().ToList(); for (int i = 0; i < lista.Count(); i++) { GameObject egg = Instantiate(prefabEgg) as GameObject; egg.GetComponent <BotonComprarHuevo>().sePuedeComprar = true; egg.GetComponent <BotonEquiparHuevo>().sePuedeEquipar = false; egg.transform.name = lista [i].Category; egg.GetComponentInChildren <UILabel> ().text = "Huevo " + lista [i].Category + " Precio: " + lista[i].Price; egg.transform.parent = parentGrid.transform; egg.transform.localScale = new Vector3(1, 1, 1); } } PlayerDAO playerDAO = new PlayerDAO(); labelOroActual.GetComponent <UILabel>().text = "Oro: " + playerDAO.GetPlayer().Gold; parentGrid.GetComponent <UIGrid> ().repositionNow = true; actualizarTienda = false; } }
void OnClick() { if (sePuedeComprar) { ItemsOwnedDAO itemsOwned = new ItemsOwnedDAO(); ItemsBasicDAO itemsBasic = new ItemsBasicDAO(); PlayerDAO playerDAO = new PlayerDAO(); int precioItem = itemsBasic.GetItemBasic(transform.name).Price; if (precioItem > playerDAO.GetPlayer().Gold) { UIController.instance.MostrarPanelMensaje("No dispones del oro suficiente para comprar eso"); } else { playerDAO.UpdateGold(playerDAO.GetPlayer().Gold - precioItem); itemsOwned.CreateItemOwned(transform.name); UIController.instance.MostrarPanelTienda(); } } }