C# 对于Input.Gettouch(0.phase==TouchPhase.Moved,如何在数组中存储所有触摸位置?

C# 对于Input.Gettouch(0.phase==TouchPhase.Moved,如何在数组中存储所有触摸位置?,c#,android,unity3d,C#,Android,Unity3d,我的尝试如下 void Update () { if(Input.touchCount>0&&Input.GetTouch(0).phase==TouchPhase.Moved) {while(Input.GetTouch(0).phase==TouchPhase.Moved) { touches[i]= Input.GetTouch (0).position;

我的尝试如下

void Update () {
        if(Input.touchCount>0&&Input.GetTouch(0).phase==TouchPhase.Moved)
        {while(Input.GetTouch(0).phase==TouchPhase.Moved)
            {
                touches[i]= Input.GetTouch (0).position;
                i = i + 1;
            }
错误出现在触摸[i]=Input.GetTouch(0.position)的行中;
请帮忙

所有触摸位置都已存储在
Input.toucks
中,它返回一组
touch
对象

对于您的情况,您仍然可以通过查询
foreach(输入.touch中的touch-touch)
循环中的
touch.phase
来访问
阶段。出现错误的原因是,foreach循环不使用索引变量
i
。这将帮助您存储具有
TouchPhase.Moved
作为阶段的触摸位置。确保职位的
列表
在相关范围内

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);
        }
    }
 }
List touchMovedPositions=new List();
如果(Input.touchCount>0)
{
foreach((在Input.Touch中触摸)
{
如果(touch.phase==TouchPhase.Moved)
{
touchMovedPositions.Add(touch.position);
}
}
}

所有触摸位置都已存储在
输入中。触摸
,它返回一组
触摸
对象

对于您的情况,您仍然可以通过查询
foreach(Input.touch中的touch)中的
touch.phase
来访问
阶段
loop。出现错误的原因是,foreach loop不使用索引变量
i
。这将帮助您存储具有
TouchPhase.移动的
作为阶段的触摸位置。确保位置的
列表
在相关范围内

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);
        }
    }
 }
List touchMovedPositions=new List();
如果(Input.touchCount>0)
{
foreach((在Input.Touch中触摸)
{
如果(touch.phase==TouchPhase.Moved)
{
touchMovedPositions.Add(touch.position);
}
}
}