With DoTween Unity, is there a way to get a callback triggered when a tweening is 50% complete?

901 views Asked by At

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

1

There are 1 answers

1
Çağatay IŞIK On

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;
    }
});