1

I'm using Unity3D and DoTweeen free version to make some simple animations. I have been using OnComplete callback a lot, but I'm wondering how I can get a callback that is triggered when half of the animation is completed? I've checked DoTween website and google, but found no such topic.

Thanks

solidcomer
  • 419
  • 6
  • 18
  • hmm good question, I don't know if DoTween has an In-build method, but I think that I will make a double animation, so if your animation is going from point A to B, I will make two animations, one from A to middle of B, throw the callback, and in paralel (cause DoTween allows you to do that) I will make an animation from middle B to B. – Lotan Jan 09 '23 at 18:55
  • 1
    @Lotan thank you, this is also a good idea which is maybe more flexible in some cases. – solidcomer Jan 09 '23 at 21:35

1 Answers1

3

This should give a basic idea. TweenerCore has a variable called position which is basically the time position of the tween that goes from 0 to duration.

float duration = 4.0f; // duration of the animation in seconds
float halfTime = duration * 0.5f; // half time
bool isHalfwayPassed = false;
var tween = transform.DOMove(_targetTransform.position, duration);
tween.OnUpdate(() =>
{
    if(tween.position >= halfTime && !isHalfwayPassed)
    {
         Debug.Log($"Half way passed");
         isHalfwayPassed = true;
    }
});
Çağatay IŞIK
  • 937
  • 6
  • 17