- Home /
Screen to view point?
Hi, this is weird question but can someone please explain ScreenToViewPoint to me?
function Update () {
transform.position = camera.main.ScreenToViewportPoint(Input.mousePosition);
}
If I want to make an object move to wherever the cursor goes, how would I do that using this script?
Comment
Answer by Mike 3 · Feb 02, 2011 at 07:31 AM
ScreenToViewportPoint maps 0->ScreenSize to 0->1 (basically divides x by Screen.width, y by Screen.height). It's almost certainly not what you need.
I would look into either ScreenToWorldPoint or Physics.Raycast, depending on whether your game is 2D or not
Answer by Cam 1 · Feb 02, 2011 at 07:42 AM
I suggest using Input.mousePosition and using that in conjunction with ScreenToWorldPoint, then transform the position.