public void Buy() { var text = selectedItemSlot.transform.Find("Price").GetComponent <Text>().text; var price = Convert.ToInt32(text.Remove(text.Length - 1)); if (playerData.Money - price >= 0) { playerData.Money -= price; Item item = selectedItemSlot.transform.Find("Item").GetComponent <Item>(); if (item != null) { itemSlotManagerInventory.AddItemToInventorySlot(item.GetType(), 1); } } currentSelectedObj = null; }
protected virtual void Update() { if (isCollided && GetComponent <BoxCollider2D>().enabled) { GetComponent <SpriteRenderer>().enabled = false; GetComponent <BoxCollider2D>().enabled = false; itemSlotManager.AddItemToInventorySlot(typeof(T), 1); if (!soundHasPlayed) { soundHasPlayed = true; audioSource.PlayOneShot(sound); } if (soundHasPlayed && !audioSource.isPlaying) { Destroy(this.gameObject); } } if (soundHasPlayed && !audioSource.isPlaying) { Destroy(this.gameObject); } }