【发布时间】:2018-08-02 08:20:07
【问题描述】:
我是 C# Unity 的新手,我刚刚学到了一些东西来开始和 我正在制作一个简单的带有触摸增量的 2D 触摸控件,以在屏幕上的任意位置使用触摸来翻译游戏对象,然后拖动以沿着触摸方向移动不要触摸位置。
例如 Rise Up 2D Game Like 控件,其中 Sphere 由触摸拖动控制。
但问题是当我在不同的屏幕尺寸上测试它时,翻译或触摸速度是不同的。
如果屏幕尺寸小,如 640x800 触摸速度慢。
如果屏幕尺寸很大,比如 1440x2560 触摸速度很快。
这是我正在使用的示例代码。
private Touch firstTouch;
public Vector3 dragDistance;
private Vector3 StopDrag;
public Transform player;
void FixedUpdate () {
if (Input.touchCount > 0)
{ firstTouch = Input.GetTouch(0);
if (Input.GetTouch(0).phase == TouchPhase.Moved)
{
dragDistance = firstTouch.deltaPosition;
player.transform.Translate(dragDistance / 100 );
}
if (Input.GetTouch(0).phase == TouchPhase.Stationary)
{
dragDistance = StopDrag ;
}}}
提前感谢我的英语不好
【问题讨论】:
标签: c# android ios unity3d touch