//--------------------------------------------------------------- void OnTriggerEnter2D(Collider2D col) { if (col.gameObject.GetComponent <GoldCoin>()) { int goldCoinVal = col.GetComponent <GoldCoin>().GetGoldCoinValue(); inventory.AddCoin(goldCoinVal); col.GetComponent <GoldCoin>().CoinDestroy(); } else if (col.GetComponent <ItemLoot>()) { ItemLoot droppedLoot = col.GetComponent <ItemLoot>(); Item itemInLoot = droppedLoot.GetDroppedItem(); rewardToObtain.AddToUltimateReward(itemInLoot); droppedLoot.ItemLootDestroyed(); } }