If you see no debug statements in the console, then your for loop is not being reached. Try to debug before the for loop. Print out some values, find out where the code is getting to.
actually, I explained badly my problem… (sorry for my english ^^)… The probleme is that the console shows “nothing under the mouse” even if I have a slot under…
Ok i had a look at OnPointerEnter(), but when I drag an item, it follows the mouse position. So if i use onPointerEnter, it will only detect the item instead of the slots under.
I tried to disable the collider, but I can’t drag any item without it…
Is there a way to ignore my item in my onPointerEnter() function ?
Add a canvas group to your item (doesn’t need a collider , btw) and when you’re dragging, set the canvas group “blocks raycast” to false. Come to think of that, you can probably do that on the image, also. Anyways, that’s how I learned (canvas group)
Restore the blocks raycast after you drop it.
methos5k I tried your solution but the problem is the same. with a canvasGroup + block Raycast = false, i can’t drag my item.
Maybe i did something wrong with my Dragging code :
Yes, you have to disable it when you begin dragging & re-enable it at the end
Otherwise, you can’t drag as you noticed.
When it’s disabled, your pointer events will “pass through” though, which is what you want…
Well, OnEndDrag happens when you’re done dragging (and is called on the object you’re dragging*)… Like I see you are attempting to mimic drop in some way by updating the pointerEnter it looked like.
OnDrop happens when you’re dragging an object, and then (let’s call it a slot - underneath - has an OnDrop interface), that place underneath will receive that event…
Ok I did it with onDrop, but now i have two separate scripts…One on the grid Layout that contain all the slot and which manage the inventory (for instance an object with positon = 3 will be on the third slot)… To do that i create a class named “slot” which contain an item, a int (for amount) and a position… but how to change these variables since they are in another file…
Or actually, how to get the previous position of the dragged item ? Is that PressPosition ?
Just 1 script manages all of the slots? Or one on each slot?
if it’s one you can reference it just in a variable on each drop script.
if it’s on each slot, that you drag… you can look it up when the drop happens.
I think it’s eventData.pointerDrag.GetComponent()
My aim is to determine if the item is above a slot or not…
But this doesn’t work…
I think I have a problem with || because during my studies I learned that there was a inclusive way and another…
Ok I found, the answer was:
if (LastSlot == null || (!LastSlot.name.Contains("Slot") && !LastSlot.transform.parent.name.Contains("Slot"))) {