Recording coordinates while dragging

Hi all.
In my game, i want to drag and drop an image, and then record which image has been dragged (there are multiple images). So basically, I want to record the id of the image on ‘dragend’.

I’ve tried doing gameObject.id and gameObject.key but it doesn’t work.

I was thinking I know the coordinate of each image at ‘dragstart’ so if I could record the cordinate of the image at dragstart and dragend, i would know which image it is.

I really appreciate any help.

If you are listening to the drag events on the game object, then the game object itself is the context of the event (this). If you are listening to the Input system, then it’s returned as gameObject in the event.

Not sure what you are assigning as .id or .key, but you might want to use the existing .name, or store things in .data with DataManager.

@prob thank you so much for your reply.

I have ten individual images and I want to record which one the user is dragging.
How would I use .name or .data in this context?

You can use the DataManager to set and get data.

1 Like