Demigiant / dotween

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

Dotween infinite loop not stopping #577

Closed romanokeser closed 2 years ago

romanokeser commented 2 years ago

I can't figure out what I'm doing wrong. I made a method that I call to either start or end the DOFade animation but the sequence doesn't stop.

private void FullscreenIconFadeAnimation(bool isAnimation)
        {
            Sequence sequence = DOTween.Sequence();//sequence for fullscreen btn icon

            if (isAnimation)
            {
               // sequence.Play();
                sequence.Append(_fullscreenIconCG.DOFade(0f, 1f))
                    .Append(_fullscreenIconCG.DOFade(1f, 1f))
                    .SetLoops(-1, LoopType.Restart);
            }
            else
            {
                _fullscreenIconCG.DOFade(0f, 0.5f);
                sequence.Kill();
                //sequence.SetAutoKill();

            }
        }

Neither sequence.Kill() or sequence.SetAutoKill() works. The sequence.Kill is called but right after that the sequence.Start is called again even tho I call FullscreenIconFadeAnimation(true) once on button click.

Demigiant commented 2 years ago

Ahoy! You are creating a local reference to sequence that exists only inside the method, so when you call that method FALSE that sequence ref is not the same. You should have your sequence variable stored outside the method, and only assign it inside it

Demigiant commented 2 years ago

See example (be sure you're not calling it TRUE twice in a row tho, or add some checks for it)

Sequence sequence;

private void FullscreenIconFadeAnimation(bool isAnimation)
        {
            if (isAnimation)
            {
                sequence = DOTween.Sequence();//sequence for fullscreen btn icon
                sequence.Append(_fullscreenIconCG.DOFade(0f, 1f))
                    .Append(_fullscreenIconCG.DOFade(1f, 1f))
                    .SetLoops(-1, LoopType.Restart);
            }
            else
            {
                _fullscreenIconCG.DOFade(0f, 0.5f);
                sequence.Kill();

            }
        }