UNITY touch position to world position 2D

只愿长相守 提交于 2019-12-14 03:47:50

问题


How can I transform the touch position (On phones) to world position. For instance if my phone's screen size is 1440 by 2560 and my touch position on the phone is X 600 Y 700. How can I transform that position to world position on unity?

I need that so I can know where the user put his finger.


回答1:


There is a method that already does that for you. Have a look at Camera.ScreenToWorldPoint.

Once you have a reference to the desired camera you can use it like this:

Vector2 touchPos = Input.touches[0].position;

Vector3 touchPosinWorldSpace = camera.ScreenToWorldPoint(new Vector3(touchPos.x, touchPos.y, camera.nearClipPlane));


来源:https://stackoverflow.com/questions/26369291/unity-touch-position-to-world-position-2d

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!