Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

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

       }

       }

Answers

  • HNJHNJ Member

    See the Tweener docs, does it is not listed how to update them during runtime ?


    So, it likes that you didn't set the private variable Tweener transitionTweener value in start.

    And you asked this question on answers.unity.com also...

Sign In or Register to comment.