Demigiant / dotween

A Unity C# animation engine. HOTween v2
http://dotween.demigiant.com
Other
2.33k stars 348 forks source link

How do I call the same component on complete? #556

Open CarloskHard opened 2 years ago

CarloskHard commented 2 years ago

So I have an array of images that moves with "DoMoveX" and I want them to vibrate, so I move the a little to the right, the doble that to the leff a few times with a loop and then return to the original pos. The only way I've been able to do it is by doing this("Circulos" means "circles"):

for (int i = 0; i < digitos; i++) { circulos[i].GetComponent<Transform>().DOMoveX(circulos[i].GetComponent<Transform>().position.x + amplitud, .04f).SetId(i).SetEase(Ease.InOutSine).OnComplete(() => { for (i = 0; i < digitos; i++) { circulos[i].GetComponent<Transform>().DOMoveX(circulos[i].GetComponent<Transform>().position.x - amplitud * 2, .04f).SetEase(Ease.InOutSine).SetLoops(5, LoopType.Yoyo).OnComplete(() => { for (int y = 0; y < digitos; y++) circulos[y].GetComponent<Transform>().DOMoveX(circulos[y].GetComponent<Transform>().position.x + amplitud, .04f).SetEase(Ease.InOutSine); }); } }); }

However that create a ton of Tweens, which I think gives problems. The problem is that I can't just call the tween on the same image becuase if I do this it doesn't work:

for (int i = 0; i < digitos; i++) { circulos[i].GetComponent<Transform>().DOMoveX(circulos[i].GetComponent<Transform>().position.x + amplitud, .04f).SetId(i).SetEase(Ease.InOutSine).OnComplete(() => { circulos[i].GetComponent<Transform>().DOMoveX(circulos[i].GetComponent<Transform>().position.x - amplitud * 2, .04f).SetEase(Ease.InOutSine).SetLoops(5, LoopType.Yoyo).OnComplete(() => { for (int y = 0; y < digitos; y++) circulos[y].GetComponent<Transform>().DOMoveX(circulos[y].GetComponent<Transform>().position.x + amplitud, .04f).SetEase(Ease.InOutSine); }); }); }

Any help? I've think of using sequences or ID but I get confused.Thanks