// ***************************************************************************************************************** #endregion // ***************************************************************************************************************** // ***************************************************************************************************************** #region Private Functions // ***************************************************************************************************************** private void HandleInteraction(Collider2D _other) { // Check if the other collider that we hit has a ItemPouch on it ItemPouch otherItemPouch = _other.GetComponent <ItemPouch>(); // Check also if the other collider has a CurrencyPouch CurrencyPouch otherCurrencyPouch = _other.GetComponent <CurrencyPouch>(); // Both ItemPouch and CurrencyPouch are needed to buy if (otherItemPouch != null && otherCurrencyPouch != null) { // Check if the other collider has enough currency if (otherCurrencyPouch.GetCurrencyValue(m_currencyName) >= m_currencyCost) { // The player has enough money. We can buy the item! // Take away the cost from the player's currency otherCurrencyPouch.SpendCurrency(m_currencyName, m_currencyCost); // Add to the ItemPouch otherItemPouch.AddItem(m_itemName, m_amount); // If we should destroy this object, do so if (m_destroyOnCollect) { Destroy(gameObject); } // If we have a sound to play, play it if (m_collectSound) { // Play the sound for collecting at this locaiton AudioSource.PlayClipAtPoint(m_collectSound, transform.position); } } // end if (has enough money) // If they don't have enough money, don't do anything. } // end if (has item pouch and currency pouch) } // end HandleInteraction()
// ***************************************************************************************************************** #endregion // ***************************************************************************************************************** // ***************************************************************************************************************** #region Private Functions // ***************************************************************************************************************** private void HandleInteraction(Collider2D _other) { // Check if the other collider that we hit has a ItemPouch on it ItemPouch itemPouch = _other.GetComponent <ItemPouch>(); if (itemPouch != null) { // Add to the ItemPouch itemPouch.AddItem(m_itemName, m_amount); // If we should destroy this object, do so if (m_destroyOnCollect) { Destroy(gameObject); } // If we have a sound to play, play it if (m_collectSound) { // Play the sound for collecting at this locaiton AudioSource.PlayClipAtPoint(m_collectSound, transform.position); } } }