Why Rect.Contains is not picking up certain area in Y axis.
Hi, ive been implementing base for Diablo like inventory system(X * Y slots with different sized items), which haven't been simple as i initially thought, but until now i have managed to make progress.
I can actually click any of the rects in the grid and it does draw the item texture in correct place if theres nothing yet, then click over the texture and it shrinks and starts to get moved relative to the mouse pointer which is what i intented, but...
this image will tell more than thousand words.
The texture is quite big for testing purposes, Rect.Contains method works inside the yellow area, but not on the spots marked with red X, which is something i couldn't figure out, maybe its something obvious for more trained eyes.
Here is the code where i go througth the inventory starting from top left corner to hit the texture(or its rect) first before the "underlying" smaller rects in the grid.
bool isClickInsideRect(Vector2 PointOfClick) {
PointOfClick.y = Screen.height - PointOfClick.y;
for(int X = 0; X < xSlots; X++) {
for(int Y = 0; Y < ySlots; Y++) {
if(InventorySlots[X, Y].rect.Contains(PointOfClick)) {
if(InventorySlots[X, Y].Texture == null) {
InventorySlots[X, Y].Texture = ItemTexture2D;
textureToDrag = null;
} else {
textureToDrag = InventorySlots[X, Y].Texture;
InventorySlots[X, Y].resetSize(); InventorySlots[X, Y].Texture = null;
}
return true;
}
}
}
return false;
}
Its same for all locations and sizes of textures i try to use, Under the top left corner of the texture rect.Contains does not return true, which i find bit odd since it does return true everywhere else over the texture(rect).
Your answer
![](https://koobas.hobune.stream/wayback/20220612150319im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
rect.contains() not working? 2 Answers
Rect.Contains not working correctly 0 Answers
Rect.Overlap not working propely? 0 Answers
I have an error and don't know what the cause is, help? 1 Answer
Visualize BoxCast Rect 1 Answer