unity3d 如果在移动过程中目标位置发生变化,如何更新DOMoveY中的目标位置

5us2dqdw  于 2023-03-03  发布在  其他
关注(0)|答案(1)|浏览(252)

如何更新DOMoveY中的目标位置,如果在移动目标位置改变,就像我运行的功能与持续时间为1f,如果在该1f目标位置改变,我如何在DOMoveY中更新?这里是代码

for (int col = 0; col < gridColumns; col++)
{

    for (int row = 0; row < gridRows; row++)
    {
        if (gridPositions[row, col].tag == "empty")
        {
            int c_row = (row + 1) > 6 ? 6 : (row + 1);
            if (gridPositions[c_row, col].tag != "empty")
            {
                if (c_row < 6)
                {

                    gridPositions[row + 1, col].transform.DOMoveY(EmptyBlocks[row, col].transform.position.y, 1f, false);
                    gridPositions[row, col] = gridPositions[row + 1, col];

                }

            }
        }

    }
}
dly7yett

dly7yett1#

可以通过组合OnUpdateChangeEndValue函数来实现这一点。在ChangeEndValue函数中,需要传递所需的可以更改/更新的Vector 3。

for (int col = 0; col < gridColumns; col++)
{      
    for (int row = 0; row < gridRows; row++)
    {
        if (gridPositions[row, col].tag == "empty")
        {
            int c_row = (row + 1) > 6 ? 6 : (row + 1);
            if (gridPositions[c_row, col].tag != "empty")
            {
                if (c_row < 6)
                {
                                
                    var moveTween = gridPositions[row + 1, col].transform.DOMoveY(EmptyBlocks[row, col].transform.position.y, 1f, false);
                    var updatedVector3 = new Vector3(gridPositions[row + 1, col].transform.position.x, EmptyBlocks[row, col].transform.position.y, gridPositions[row + 1, col].transform.position.z);
                    moveTween.OnUpdate(()=>moveTween.ChangeEndValue(updatedVector3, true));
                    gridPositions[row, col] = gridPositions[row + 1, col];
                 }
            }
        }
    }
}

相关问题