private void HitMirrorBadly(CapsulesHandler handler) { Debug.Log(string.Format("Crashing with direction {0}", Movement)); if (!bouncing) { handler.Crashed(); } }
private void OnCollisionEnter2D(Collision2D collision) { Mirror mirror = collision.gameObject.GetComponentInParent <Mirror>(); Capsule capsule = collision.gameObject.GetComponent <Capsule>(); CapsulesHandler handler = GetComponentInParent <CapsulesHandler>(); if (mirror != null) { switch (mirror.orientation) { case Mirror.Orientation.LEFT_DOWN: switch (Movement) { case Direction.UP: HitMirrorBadly(handler); break; case Direction.RIGHT: HitMirrorBadly(handler); break; case Direction.LEFT: Bounce(Direction.UP); break; case Direction.DOWN: Bounce(Direction.RIGHT); break; } break; case Mirror.Orientation.LEFT_UP: switch (Movement) { case Direction.UP: Bounce(Direction.RIGHT); break; case Direction.RIGHT: HitMirrorBadly(handler); break; case Direction.LEFT: Bounce(Direction.DOWN); break; case Direction.DOWN: HitMirrorBadly(handler); break; } break; case Mirror.Orientation.RIGHT_UP: switch (Movement) { case Direction.UP: Bounce(Direction.LEFT); break; case Direction.RIGHT: Bounce(Direction.DOWN); break; case Direction.LEFT: HitMirrorBadly(handler); break; case Direction.DOWN: HitMirrorBadly(handler); break; } break; case Mirror.Orientation.RIGHT_DOWN: switch (Movement) { case Direction.UP: HitMirrorBadly(handler); break; case Direction.RIGHT: Bounce(Direction.UP); break; case Direction.LEFT: HitMirrorBadly(handler); break; case Direction.DOWN: Bounce(Direction.LEFT); break; } break; default: break; } } else if (capsule != null) { if (capsule == handler.StartingCapsule) { handler.Crashed(); } else { handler.Reached(); } } else { handler.Crashed(); } }