// Update is called once per frame // void Update() // { // // } void OnTriggerEnter2D(Collider2D col) { if (col.gameObject.CompareTag("Box")) { boxOnTop = col.gameObject.GetComponent <NumberBox>(); boxOnTop.SetSlot(this); Debug.Log("[BoxSlot] Got box with value: " + boxOnTop.GetNumberValue(), this); foreach (var slotsObserver in observers) { slotsObserver.CalculateResult(); } } }
void OnTriggerExit2D(Collider2D col) { if (col.gameObject.CompareTag("Box")) { if (boxOnTop.GetSlot() == this) { boxOnTop.SetSlot(null); } boxOnTop = null; Debug.Log("[BoxSlot] Box detached", this); foreach (var slotsObserver in observers) { slotsObserver.CalculateResult(); } } }