Demigiant / dotween

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

SetDelay() not working on Restart() #546

Closed hayone1 closed 2 years ago

hayone1 commented 2 years ago

I have some tweens I created and want to replay then in an infinite loop but with a separate random start delay for each loop. Unfortunately, all the tweens seem to restart at the same time immediately after they complete with no regard for the new delay time. The tweens are created can played in an async method that is called in start. I really appreciate you help, thanks.

Code Snippet: while (!token.IsCancellationRequested){ foreach(var _bubbleTweener in _bubbleTweeners){ if (_bubbleTweener.IsComplete()){ _bubbleTweener.SetDelay(Random.Range(animTime, animTime*10)).Restart(); } }

        await UniTask.NextFrame();

    }
hayone1 commented 2 years ago

ok, I figured out that when I created the tweens, they were set to loop infinitely (-1) so they never actually change isComplete() to true, so I changed that. I also used the overload method of Restart to implement the random delay:

Code: while (!token.IsCancellationRequested){ foreach(var _bubbleTweener in _bubbleTweeners){ if (_bubbleTweener.IsComplete()){ _bubbleTweener.Restart(includeDelay: true, changeDelayTo: Random.Range(animTime, animTime*2)); } } await UniTask.NextFrame();

    }