UNITY触摸位置到世界位置2D [英] UNITY touch position to world position 2D
本文介绍了UNITY触摸位置到世界位置2D的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将触摸位置(在手机上)转换为世界位置。例如,如果我的手机的屏幕尺寸是1440 x 2560,而我在手机上的触摸位置是X 600 Y700。如何将该位置转换为统一的世界位置?
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.
推荐答案
已经有一种方法可以为您完成此操作。看看 Camera.ScreenToWorldPoint 。
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));
这篇关于UNITY触摸位置到世界位置2D的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文