我想要迭代7个位置,它们在x轴上都有4.5的差异,因此Position0 = 0,Position1 = 4.5&位置= 9,依此类推。
但是,当我从Position0转到Position1时,x似乎继续增长4.5。迭代通过数组工作,但它每帧增加4.5。我做错了什么?
void Start () {
_positionArray[0] = position0;
_positionArray[1] = position1;
_positionArray[2] = position2;
_positionArray[3] = position3;
_positionArray[4] = position4;
_positionArray[5] = position5;
_positionArray[6] = position6;
endPosition = position0;
}
public void changeDestination()
{
if (_leapManager.swipePerformed)
{
swipeDirection = _leapManager.swipeDirection;
if (swipeDirection == "left" && posInArray >= 0 && posInArray < 5)
{
Debug.Log("called");
posInArray++;
endPosition.position = _positionArray[posInArray].position;
}
else if (swipeDirection == "right" && posInArray <= 5 && posInArray > 0)
{
posInArray--;
endPosition.position = _positionArray[posInArray].position;
}
}
}
// Update is called once per frame
void Update () {
transform.position = Vector3.Lerp(transform.position, endPosition.position, speed * 3.0f * Time.deltaTime);
}