Table of Contents

Tween

Here we have some examples on how to build Tweens

Basic

  1. Creating the tween with a time duration of 10s
  2. Setting the loop type to PingPong(back and forth)
  3. Setting the loop count to 4
  4. Setting a delay of 4 seconds
  5. Adding an event that is executed before the start of the tween
  6. Adding an event that is executed after the completion of the tween
  7. Starting the tween
Tween tween = new Tween(10f)
    .SetLoopType(LoopType.PingPong)
    .SetLoopCount(4)
    .SetDelay(4f)
    .OnStarting(() => Debug.Log("Before start."))
    .OnCompleted(() => Debug.Log("After completion!"))
    .Start();

Simple Motion

  1. Creating the tween with a time duration of 1s
  2. Selecting the object to be animated
  3. Applying the Move motion
  4. Starting the tween
Tween tween = new Tween(1f)
    .For(transform)
        .Move(Vector3.one)
    .Start();

Multiple Motions

  1. Creating the tween with a time duration of 1s
  2. Selecting the object to be animated
  3. Applying the Move motion
  4. Applying the Rotate motion
  5. Applying the Scale motion
  6. Starting the tween

Note: All 3 motions are applied at the same time, for the same object. They are all part of the same tween

Tween tween = new Tween(1f)
    .For(transform)
        .Move(Vector3.one)
        .Rotate(Vector3.up * 360)
        .Scale(Vector3.one * 3)
    .Start();

Multiple Objects

  1. Creating the tween with a time duration of 1s
  2. Setting the easing to EaseInSine
  3. Selecting the first object to be animated
  4. Applying the Move motion
  5. Selecting the second object to be animated
  6. Applying the Move motion
  7. Selecting the third object to be animated
  8. Applying the Rotate motion
  9. Applying the Scale motion
  10. Starting the tween

Note: The tween settings are applied to all the motions for all the objects

Tween tween = new Tween(1f)
    .SetEasing(Easing.EaseInSine)
    .For(transform1)
        .Move(Vector3.one)
    .For(transform2)
        .Move(Vector3.one * 2)
    .For(transform3)
        .Rotate(Vector3.up * 360)
        .Scale(Vector3.one * 3)
    .Start();

Extensions

In order to apply a tween to an object straight away, you can use the "Tween" extension method.

  1. Selecting the object to be animated
  2. Applying the extension method(available for any object) and setting the time
  3. Applying the Move motion
  4. Applying the Rotate motion
  5. Applying the Scale motion
  6. Starting the tween
Tween tween = transform
    .Tween(1f)
    .SetTimeScale(2f)
        .Move(Vector3.one)
        .Rotate(Vector3.up * 360)
        .Scale(Vector3.one * 3)
    .Start();

Async

In the first example, a tween is being awaited upon staring it.
In the second example, a tween is started, something else is done, and if the tween is not yet finished, it can be awaited to finish.
await new Tween(1f)
    .For(transform)
    .SetSkipFrames(20)
        .Move(Vector3.one)
    .StartAsync();
Tween tween = new Tween(1f)
    .For(transform)
    .SetSkipFrames(20)
        .Move(Vector3.one)
    .Start();

await DoSomethingElseAsync();

await tween.AsAsync();