It would be great if somebody could help me out with this. I am attaching a screenshot of the game that I m developing. I have to drag the cards out from the GUI and place it on the ground which I have divided into grids. 1. I would drag the required card on GUI. When mouse exits the GUI and enters the Viewport, I need to instantiate a GameObject at the mouse Position with the same texture overlaid. I am not sure how to determine the Mouse Position on exit (in World Coordinates) in the above case 2. Also, with the mouse pressed I should continue dragging the instantiated card to a desired grid. For this I did Code (csharp): var cardObj = GameObject.FindWithTag("card"); screenSpace = Camera.main.WorldToScreenPoint(cardObj.position); curScreenSpace = Vector3(Input.mousePosition.x, Input.mousePosition.y, screenSpace.z); curPosition = Camera.main.ScreenToWorldPoint(curScreenSpace); Again the ScreenToWorld conversion works well only for a certain region on the screen. The mouse movement and the object is totally out of sync in other regions. If somebody could point out where I m going wrong, it would be very helpful.
http://unity3d.com/support/documentation/ScriptReference/Camera.ScreenToWorldPoint.html Just feed it the mouse coordinates and you're golden. There's a plethora of examples about on the forums.
What would be the 'z' value in this case? I did try using camera.nearplane as z. The cards were totally displaced.