Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

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