A simple 2D isinbox function can be:
bool IsInBox(int x1, int y1, int width1, int height1, int x2, int y2, int width2, int height2) { int right1 = x1 + width1; int right2 = x2 + width2; int bottom1 = y1 + height1; int bottom2 = y2 + height2; // Check if top-left point is in box if (x2 >= x1 && x2 <= right1 && y2 >= y2 && y2 <= bottom1) return true; // Check if bottom-right point is in box if (right2 >= x1 && right2 <= right1 && bottom2 >= y2 && bottom2 <= bottom1) return true; return false; }
Not sure if xd works though
Or you can use Rect.Intersect ()
source share