2017-10-17 12 views

回答

2

所有触摸位置已存储在Input.touches中,该位置返回Touch对象的集合。 An example is laid out in the Unity documentation here.

对于你的情况,你仍然可以通过在foreach (Touch touch in Input.touches)循环查询touch.phase访问phase。您遇到错误的原因是,foreach循环不会使用索引变量i。这将帮助您存储具有TouchPhase.Moved作为阶段的触摸位置。确保职位的List<Vector2>位于相关范围内。

List<Vector2> touchMovedPositions = new List<Vector2>(); 
if(Input.touchCount > 0) 
{ 
    foreach((Touch touch in Input.touches) 
    { 
     if(touch.phase == TouchPhase.Moved) 
     { 
      touchMovedPositions.Add(touch.position); 
     } 
    } 
} 
+1

感谢您的重播! Input.touches很好 –