diff --git a/Assets/Scripts/Items/ItemObject.cs b/Assets/Scripts/Items/ItemObject.cs index ad53f48..73cca34 100644 --- a/Assets/Scripts/Items/ItemObject.cs +++ b/Assets/Scripts/Items/ItemObject.cs @@ -15,6 +15,8 @@ public abstract class ItemObject : MonoBehaviour [SerializeField] private Vector2 conveyorDirection = Vector2.zero; [SerializeField] private ConveyorPO currentConveyor; + [SerializeField] private IOPort ioPort = null; + public abstract void OnSpawn(); @@ -33,6 +35,7 @@ public abstract class ItemObject : MonoBehaviour private void OnCollisionEnter2D(Collision2D collision) { + // Stack Item if (collision.gameObject.GetComponent() != null) { ItemObject collisionItemObject = collision.gameObject.GetComponent(); @@ -52,6 +55,12 @@ public abstract class ItemObject : MonoBehaviour } } } + + // IOPort + if (collision.gameObject.GetComponent() != null) + { + ioPort = collision.gameObject.GetComponent(); + } } // Gets the temporary pivot point based on the conveyor direction @@ -132,6 +141,20 @@ public abstract class ItemObject : MonoBehaviour UpdateWithoutConveyor(); } #endregion + #region IOPort + if (ioPort != null) + { + if (ioPort.item == itemSO) + { + stackSize = ioPort.IncreaseItemCount(stackSize); + if (stackSize == 0) + { + Despawn(); + } + } + } + + #endregion } private void UpdateWithoutConveyor() // Handles the item when it is not on a conveyor