So in my inventory I have this Picker object that’s supposed to pick up items and have them follow the mouse. The picker is an empty object with a background (and eventually the picked up item) as children. The “Picker” is a child of “Inventory” which is a child of my “UI” canvas object. So UI/Inventory/Picker. I was making the picker follow the mouse with:
transform.localPosition = Input.mousePosition - myCanvas.transform.localPosition;
Everything was working fine until I later made some pivot-related changes to the slots and inventory, now the picker doesn’t follow the cursor ‘unless’ I make it a direct parent to UI instead of Inventory, so then I would have UI/Inventory, and UI/Picker, i.e.
UI
-- Inventory
-- Picker
as opposed to:
UI
-- Inventory
---- Picker
not just that, I also have to anchor the picker to the bottom left and use the same code or just say:
rectTransform.anchoredPosition = Input.mousePosition;
I would like for the Picker to be a child of Inventory and not UI and still be able to follow the mouse position. The new UI isn’t making it easy with all its pivot/anchors, etc concepts.
I thought initially I could just say:
picker.transform.position = Camera.main.ScreenToWorldPoint(Input.mousePosition);
but it’s not that simple it seems…
Here’s a video demonstrating the issue - YouTube - notice how the picker doesn’t follow the exact position of the cursor when I put it under Inventory.
What do I have to do to make the picker follow the mouse’s exact position when the picker is a child of Inventory instead of UI?
Any help is greatly appreciated. Thanks.
NOTE: Inventory is anchored with ‘middle - center’ and has a pivot of ‘0, 1’