I have created a 3d grid game where you drag the playing pieces around using touch on an Android device. This part of the game works great. On the side of the screen I have a 2D menu with images of the playing pieces. I would like to be able to drag these 2D images onto the 3D game grid.
My thought is that I can spawn the 3D object as the player drags the 2D object past the edge of the 2D menu on the side. I have tried a few different solutions without success. Maybe I am going about this the wrong way.
Can anyone recommend an approach to solving this issue?
Instead of trying to figure when the tile was outside the 2D menu I just do a raycast to detect when it is over the game grid and spawn the 3D game piece at that time.
To get from a screen position (e.g. Input.mousePosition) to a real world position requires two steps. First, you convert the screen position to a ray
Then, construct a raycaster with that ray and the collider of the game board
This will return a RaycastHit, which gives you the projected screen position on the board. From there you simply use Object.Instantiate to create your object.