大lao们请问一下DoTween动画如何嵌套在for循环中啊,我想让这三个物体按照冒泡排序的算法移动,但最后结果好像不太对,就是物体没有按照预想的动画去执行,我认为应该就是DoTween对于类似的动画只执行靠后的动画,该如何解决啊,下面是代码和结果图
1.放到协程中,给动画一个时间运行
2.GetComponent可以简化
IEnumerator startMove()
{
for (int i = 0; i < Obj.Count - 1; i++)
{
for (int j = 0; j < Obj.Count - i - 1; j++)
{
if (Obj[j].transform.lossyScale.y > Obj[j + 1].transform.lossyScale.y)
{
Vector3 a = Obj[j + 1].transform.position;
Vector3 b = Obj[j].transform.position;
Obj[j + 1].transform.DOMoveX(b.x, 2);
Obj[j].transform.DOMoveX(a.x, 2);
GameObject x = Obj[j];
Obj[j] = Obj[j + 1];
Obj[j + 1] = x;
yield return new WaitForSeconds(2);
}
}
}
}