C# touch.fingerid触摸不工作
下面是我的鼠标外观脚本,它控制触摸和移动,现在我正在实现多重触摸,因为,我使用了手指ID,但在实现之后,我的触摸不起作用,不知道为什么。按默认值,滑块\u finger\u id=-1C# touch.fingerid触摸不工作,c#,unity3d,touch,unity5,C#,Unity3d,Touch,Unity5,下面是我的鼠标外观脚本,它控制触摸和移动,现在我正在实现多重触摸,因为,我使用了手指ID,但在实现之后,我的触摸不起作用,不知道为什么。按默认值,滑块\u finger\u id=-1 if (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer) { if( Input.touchCount>0 )
if (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer)
{
if( Input.touchCount>0 )
{
foreach (Touch touch in Input.touches)
{
if (touch_moving_tex.HitTest (touch.position))
{
if(touch.phase == TouchPhase.Began && touch.phase == TouchPhase.Moved && slider_finger_id ==-1)
{
if (axes == RotationAxes.MouseXAndY)
{
sensitivityX = main_fov;
noisedeltaX += ((((Mathf.Cos (Time.time) * Random.Range (-10, 10) / 5f) * noiseX) - noisedeltaX) / 100) * Time.timeScale;
rotationXtemp += (touch.deltaPosition.x * sensitivityX * sensitivity) + (noisedeltaX);
//rotationXtemp += (Input.GetTouch (0).deltaPosition.x * sensitivityX * sensitivity) + (noisedeltaX);
rotationX += ((rotationXtemp - rotationX) / 3) * Time.timeScale;
rotationX = Mathf.Clamp (rotationX, minimumX, maximumX);
sensitivityY = main_fov;
noisedeltaY += ((((Mathf.Sin (Time.time) * Random.Range (-10, 10) / 5f) * noiseY) - noisedeltaY) / 100) * Time.timeScale;
rotationYtemp += (touch.deltaPosition.y * sensitivityY * sensitivity) + (noisedeltaY);
rotationY += ((rotationYtemp - rotationY) / 3) * Time.timeScale;
rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
transform.rotation = Quaternion.Lerp (transform.rotation, Quaternion.Euler (new Vector3 (-rotationY, rotationX, 0)), 9f * Time.deltaTime);
}
}
slider_finger_id = touch.fingerId;
}
if (touch.phase == TouchPhase.Ended)
{
if (touch.fingerId == slider_finger_id)
{
slider_finger_id = -1;
}
}
}
}
事实上,我没有得到touch.fingerId,也没有存储,也没有检查特定的touch.fingerId,所以我通过这样做找到了答案。下面是脚本和执行良好。(我在下面的代码中所做的主要工作是,touch仅适用于第一次触摸,通过保存touch.fingerId按fingerId执行) 首先,我刚刚检查了触摸计数是否大于零,然后获取了触摸数组并执行foreach循环,然后检查了触摸是否在我想要的位置,然后获取了第一个触摸fingerId,并将其保存在slider\u finger\u id中,然后使用它
if (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer)
{
if( Input.touchCount>0 )
{
foreach (Touch touch in Input.touches)
{
if (touch_moving_tex.HitTest (touch.position))
{
if(touch.phase == TouchPhase.Began && slider_finger_id == -1)
{
slider_finger_id = touch.fingerId;
}
if(touch.phase == TouchPhase.Moved)
{
if (axes == RotationAxes.MouseXAndY)
{
sensitivityX = main_fov;
noisedeltaX += ((((Mathf.Cos (Time.time) * Random.Range (-10, 10) / 5f) * noiseX) - noisedeltaX) / 100) * Time.timeScale;
rotationXtemp += (touch.deltaPosition.x * sensitivityX * sensitivity) + (noisedeltaX);
//rotationXtemp += (Input.GetTouch (0).deltaPosition.x * sensitivityX * sensitivity) + (noisedeltaX);
rotationX += ((rotationXtemp - rotationX) / 3) * Time.timeScale;
rotationX = Mathf.Clamp (rotationX, minimumX, maximumX);
sensitivityY = main_fov;
noisedeltaY += ((((Mathf.Sin (Time.time) * Random.Range (-10, 10) / 5f) * noiseY) - noisedeltaY) / 100) * Time.timeScale;
rotationYtemp += (touch.deltaPosition.y * sensitivityY * sensitivity) + (noisedeltaY);
rotationY += ((rotationYtemp - rotationY) / 3) * Time.timeScale;
rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
transform.rotation = Quaternion.Lerp (transform.rotation, Quaternion.Euler (new Vector3 (-rotationY, rotationX, 0)), 9f * Time.deltaTime);
}
}
}
slider_finger_id = touch.fingerId;
}
if (touch.phase == TouchPhase.Ended && slider_finger_id == touch.fingerId)
{
slider_finger_id = -1;
}
}
}
我注意到一件事,如果我不使用slider\u finger\u id,那么它就可以工作。。但是我检查了很多次,它是-1,没有任何变化,并且
滑块\u finger\u id
设置在哪里?在第一次迭代中,值是多少?我不确定-1
是否有效。