I am creating a drag/drop chemistry builder game. I have 3D spheres as various chemical elements. In the picture below, you can see five bins of atoms. The interaction I desire is that a user can click in the area around each bin and a corresponding element will pop up near the cursor as if it were being held. As the user holds the mouse button, they can drag it into the game area and release to drop it down.
How do I go about achieving this behavior?
This is a large question… You have 5 gameobjects for each bin. You can add a script to each gameobject that will handle itself separately.
The basics would be:
Click on bin. The script will detect the click and hold (drag movement) and create a colorful circular gameobject on the mouses position.
When they let go of mouse button, transform the mouse position into world coordinates and let go of the control of the ball gameobject that was fixing it to your mouse and let it drop. (gravity and other physics will go into play)
I would read up on the following APIs:
You will be using the OnDrag, OnBeginDrag, OnEndDrag method.
You could also not use a drag, but instead a click and click technique or Pointer things. The Pointer logic is similar to the drag handlers.