2017-10-17 5 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はうまくいきます –

関連する問題