void OnTriggerEnter2D(Collider2D other) { Jammable jammable = other.transform.GetComponent <Jammable>(); if (jammable != null) { jammable.Jam(); } }
void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.CompareTag("Bread") && !collidedAlready) { Jammable jam1 = GetComponent <Jammable>(); Jammable jam2 = collision.transform.GetComponent <Jammable>(); collision.gameObject.GetComponent <MakeSandwich>().SetCollided(); var beingCarried = gameObject.GetComponent <Carriable>().IsBeingCarried(); var otherBeingCarried = collision.gameObject.GetComponent <Carriable>().IsBeingCarried(); if (!beingCarried && !otherBeingCarried) { if (jam1 != null && jam2 != null && (jam1.HasJam() || jam2.HasJam())) { SuccessSandwich(collision.gameObject); } else { FailSandwich(collision.gameObject); } } } }