public bool TryAdd(InventoryColor inventoryColor) { Debug.Log("Trying to add " + inventoryColor.Color + "to inventory"); var result = ""; foreach (var inventoryItem in InventoryItems) { if (inventoryItem is InventoryColor ic) { result += ic.Color + " "; } } Debug.Log("Content of inventory: " + result); if (InventoryItems.Contains(inventoryColor)) { Debug.Log("Inventory already contain this color"); return(false); } inventoryColor.InventoryColorChanged += InventoryColorChanged; InventoryItems.Add(inventoryColor); return(true); }
// Use this for initialization void OnTriggerEnter(Collider col) { if (col.tag.Equals("Player")) { if (InventoryColor.goldCount > 0) { InventoryColor.NoGold(); } else { col.gameObject.GetComponent <Reseter>().ResetPlayer(); } } }
private void OnTriggerEnter(Collider other) { if (other.gameObject.tag == "Player") { Destroy(gameObject); if (color.Equals("blue")) { InventoryColor.addCount(color, ballnum + 2); } if (color.Equals("gold")) { InventoryColor.addCount(color, ballnum + 6); } InventoryColor.addCount(color, ballnum); } }
public bool TryRemove(InventoryColor inventoryColor) { var result = InventoryItems.Remove(inventoryColor); if (!result) { Debug.Log("Inventory do not contain this color"); } if (result) { inventoryColor.InventoryColorChanged -= InventoryColorChanged; } return(result); }
private void InventoryColorChanged(InventoryColor inventoryColor) { ContentChanged.Invoke(InventoryItems); }