Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Question regarding LeanTween and consecutive tweens

Discussion in 'Animation' started by Poi-son, Dec 28, 2021.

  1. Poi-son

    Poi-son

    Joined:
    Dec 22, 2021
    Posts:
    33
    Hi all,

    I'm just experimenting with LeanTween.

    What I don't get is how do you execute a couple of consecutive tweens on a GameObject?
    Like, first scale it, then when it finishes do moveY, then as it completes, do some rotation... etc.

    I found a chain(?) method setOnComplete if it is used for this purpose but I'm not sure if I'm doing it correctly.
    Basically how do you tell if a tween is completed and order the script to execute another upon completion?

    At the moment I'm doing something like below...
    This seems to work fine but I'm not sure if this is performant or should be done this way.

    Code (CSharp):
    1. private void Start()
    2.     {
    3.         StartCoroutine(MyObjectAnimation());
    4.     }
    5.  
    6.  
    7.     IEnumerator MyObjectAnimation()
    8.     {
    9.         LeanTween.moveY(gameObject, gameObject.transform.position.y + 2f, 1f).setEaseInOutSine().setIgnoreTimeScale(true);
    10.         yield return new WaitForSeconds(1f);
    11.         LeanTween.moveY(gameObject, gameObject.transform.position.y - 2f, 1f).setEaseInOutSine().setIgnoreTimeScale(true).setOnComplete(RepeatAgain);
    12.         yield break;
    13.     }
    14.  
    15.     void RepeatAgain()
    16.     {
    17.         StartCoroutine(MyObjectAnimation());
    18.     }
    Thank you!
     
    thathurtabit likes this.
  2. Poi-son

    Poi-son

    Joined:
    Dec 22, 2021
    Posts:
    33
    Anyone? :oops:
    I'm pretty sure there should be a more convenient way than what I am doing there... Will be glad if someone can point it out to me. :)
     
  3. commofnahrime

    commofnahrime

    Joined:
    Mar 7, 2020
    Posts:
    1
    Hello :)

    First line cancels any Tweens already going on that game object. This solved it for me so i hope it helps :) Would try to help if it doesnt solve your issue, as far as i see it you can use this unless you need to set a variable

    LeanTween.cancel(gameObject);
    LeanTween.moveLocalX(gameObject, transform.position.x, 1f).setEaseInOutSine();