Unity3d Touch.rawPosition-Touch.Position而不是Touch.Position-(以前保存的)Touch.Position?

Unity3d Touch.rawPosition-Touch.Position而不是Touch.Position-(以前保存的)Touch.Position?,unity3d,Unity3d,比如说,我的目标是使用Touch类获得刷卡动作的长度 使用 if(touchPhase == touchPhase.Began) { touchStart = touch.Position; } else if(touchPhase == touchPhase.Ended) { Vector2 length = touch.Position - touchStart; } 及 从文档中可以看出,拖动触摸触点时,rawPosition不会改变,因

比如说,我的目标是使用Touch类获得刷卡动作的长度

使用

 if(touchPhase == touchPhase.Began)
    {
    touchStart = touch.Position;
    }
    else if(touchPhase == touchPhase.Ended) {
    Vector2 length = touch.Position - touchStart;
    }

从文档中可以看出,拖动触摸触点时,rawPosition不会改变,因此代码应该可以工作

我需要一个小小的解释


谢谢你

因为我知道行为应该是平等的。正如你所说,你自己就是

触摸触点在屏幕空间像素坐标中的第一个位置

原始位置返回触摸触点的原始位置,并且不会随着触摸的拖动而改变。如果需要触摸的当前位置,请参阅
touch.position

除了在第二段代码中

Vector2长度=touch.Position-touch.rawsposition;
增量总是当前位置减去先前位置


你可以简单地用例如

//通常,对枚举使用开关
开关(接触相)
{
案例接触阶段。开始:
touchStart=触摸位置;
打破
案件审理阶段结束:
Assert(touchStart==touch.RawPosition,“不等于:O”,this);
Vector2长度=触控位置-触控启动;
矢量2长度2=触摸位置-触摸位置;
//显然是多余的-如果第一个断言已经通过,那么这也将是多余的
Assert(length==length2,“notequal:O”,this)
打破
}
if(touchPhase == touchPhase.Ended) {
    Vector2 length = touch.RawPosition - touch.Position;
    }