public void AddToItems(Object obj) { Vegetable v = obj as Vegetable; if (v) { Debug.Log("Trying to pickup a vegetable"); Debug.Log("vegetable is: " + v.veggieType); for (int i = 0; i < itemsCarrying.Count; i++) { Vegetable v2 = itemsCarrying[i] as Vegetable; if (v2) { if (v.veggieType == v2.veggieType) { Debug.Log("Putting vegetable back"); RemoveVegetable(v2, true); return; } } } } if (itemsCarrying.Count >= maxCarryCapacity) { Debug.Log("Carry capacity at maximum"); return; } //Check to see if the vegetable we are trying to pick up is already with the player v = obj as Vegetable; if (v) { Debug.Log("Trying to pickup a vegetable"); Debug.Log("vegetable is: " + v.veggieType); //If the vegetable type is not being carried, clone it Vegetable clone = Instantiate(v); clone.GetComponent <Collider2D>().enabled = false; //Assign to one of the hands if (rightHand.transform.childCount == 0) { clone.transform.SetParent(rightHand.transform); } else { clone.transform.SetParent(leftHand.transform); } clone.transform.localPosition = Vector3.zero; clone.transform.localScale /= 2; //add it to the player's list itemsCarrying.Add(clone); return; } Salad s = obj as Salad; if (s) { //No special conditions required for salad as it's only possible to make one salad at a time Debug.Log("Trying to pickup the salad"); //Salad can't be cloned //Assign to one of the hands if (rightHand.transform.childCount == 0) { s.transform.SetParent(rightHand.transform); s.transform.localPosition = Vector3.zero; } else { s.transform.SetParent(leftHand.transform); s.transform.localPosition = Vector3.zero; } itemsCarrying.Add(s); } }