How to update Tweener with parameters in Unity3D?

Hi folks,

I’d like to move up and down a certain part of a 2D-enemy-spaceship via DoTween’s DOMoveY-shortcut. So far so good - it almost works… but when I try to change the value of the transitionTarget during gameplay the animation doesn’t change accordingly.

So the problem seems to be that the code doesn’t update the Tweener. Now I’d like to know what do I have to change of my code so that the Tweener gets updated when I change the value (via inspector) of the transitionTarget during gameplay?

This is the code:

        public float transitionTarget = 0f;
  
        private Tweener transitionTweener;
        private bool toggleTransition = true;
  
        void Start()
        {
        TransitionTween(transitionTarget);
  
        transitionTweener.OnRewind(() => {
            Debug.Log("<<- Transition played backward and completed!");
            toggleTransition = true;
        });
  
        transitionTweener.OnComplete(() => {
            Debug.Log("->> Transition played and completed!");
            if (toggleTransition) toggleTransition = false;
            else toggleTransition = true;
        });
        }
  
        void TransitionTween(float targetY) {
        transitionTweener = this.transform.DOMoveY(targetY, 3f, false)
        .SetEase(Ease.Linear)
        .SetAutoKill(false)
        .SetId("tran")
        .Pause();
        }
  
        void Update() {
        if (toggleTransition) {
            transitionTweener.PlayForward();
        }
        else {
            transitionTweener.PlayBackwards();
        }
        }

I think you will need to kill the previous tweener instance in the TransitionTween method. You have set it to false right now. Either make it true. SetAutoKill( true ). Or use DOTween.Kill(myTargetOrId)