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);
}
}
}