Is there a way to execute code when a Tween or Sequence starts (OnStart equivalent)? #90
-
I'm making an animator and i have some specific events that can't we tweened because it makes no sense (i.e changing the sprite of a GameObject, running some code at a specific time etc). |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
This question is closely tied to the one about animation caching: #88 Animation caching is possible with PrimeTween as described in the link above, but that's not a recommended way of playing animations. Instead, a simpler approach is to create an animation at the exact moment you need it. So if you do it the recommended way, then the question about OnStart() callback goes away because you can just call a method right before you start the animation: DoSomethingBeforeAnimation();
Tween.Position(...); But if you still want to go in the path of caching animations, then you can chain a callback before other animations in a Sequence. This will have the same effect as DOTween's OnStart() callback: var seq = Sequence.Create()
.ChainCallback(() => DoSomethingBeforeAnimation())
.Chain(Tween.Position(...))
seq.isPaused = true; // unpausing the animation later will call the DoSomethingBeforeAnimation() before starting animation |
Beta Was this translation helpful? Give feedback.
This question is closely tied to the one about animation caching: #88
Animation caching is possible with PrimeTween as described in the link above, but that's not a recommended way of playing animations. Instead, a simpler approach is to create an animation at the exact moment you need it. So if you do it the recommended way, then the question about OnStart() callback goes away because you can just call a method right before you start the animation:
But if you still want to go in the path of caching animations, then you can chain a callback before other animations in a Sequence. This will have the same effect as DOTween's OnStart() callback: