Unity: How to animate images with DOTween and stop loop?

4.2k Views Asked by At

for my game I am using DOTween in order to animate an image. I implemented a loop which scales my image higher and then going back to its normale scale. The problem is that I want to end the loop as soon as I press a button or enter another method. Does somebody know how I can do this? Here is the code I am using currently:

image.transform.DOScale(1.6f, 1.5f).SetEase(Ease.InOutSine).SetLoops(-1, LoopType.Yoyo);

Kind regards

1

There are 1 best solutions below

0
LafiteCandy On

You can save the Tweener with an argument, and call Kill() funtion to stop it. Try this:

Tweener tweener;
private void Awake() {
    tweener = transform.DOScale( 1.6f, 1.5f ).SetEase( Ease.InOutSine ).SetLoops( -1, LoopType.Yoyo );
}
private void PressAButton() {
    tweener.Kill();
}

if you just want to pause it, just call tweener.Pause();, and replay by tweener.Play();