protected virtual bool IsColliding(Vector2 direction, float distance, LayerMask collision) { var hits = new RaycastHit2D[10]; int hitsCount = Collider.Cast(direction, hits, distance); for (int i = 0; i < hitsCount; i++) { if ((1 << hits[i].collider.gameObject.layer & collision) != 0) { return(true); } } return(false); }