Update ItemObject.cs

This commit is contained in:
Janis
2022-06-09 18:41:12 +02:00
parent 44461ff955
commit 6391c30c60

View File

@@ -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<ItemObject>() != null)
{
ItemObject collisionItemObject = collision.gameObject.GetComponent<ItemObject>();
@@ -52,6 +55,12 @@ public abstract class ItemObject : MonoBehaviour
}
}
}
// IOPort
if (collision.gameObject.GetComponent<IOPort>() != null)
{
ioPort = collision.gameObject.GetComponent<IOPort>();
}
}
// 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