Question regarding LeanTween and consecutive tweens

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.

private void Start()
    {
        StartCoroutine(MyObjectAnimation());
    }


    IEnumerator MyObjectAnimation()
    {
        LeanTween.moveY(gameObject, gameObject.transform.position.y + 2f, 1f).setEaseInOutSine().setIgnoreTimeScale(true);
        yield return new WaitForSeconds(1f);
        LeanTween.moveY(gameObject, gameObject.transform.position.y - 2f, 1f).setEaseInOutSine().setIgnoreTimeScale(true).setOnComplete(RepeatAgain);
        yield break;
    }

    void RepeatAgain()
    {
        StartCoroutine(MyObjectAnimation());
    }

Thank you!

1 Like

Anyone? :sweat_smile:
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. :slight_smile:

Hello :slight_smile:

First line cancels any Tweens already going on that game object. This solved it for me so i hope it helps :slight_smile: 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();