UNITY position in 2D world position

How to convert touch position (on phones) to world position. For example, if my phone screen size is 1440 by 2560 and my touch position on my phone is X 600 Y 700. How can I convert that position to world position by one?

I need to be able to know where the user has placed their finger.

+3


source to share


1 answer


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

Once you have a link 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));

      

+2


source







All Articles