DOTWeen generic tweener

DOTWeen generic tweener

Most generic way to write tweener with DOTWeen I usually can’t remember

DOTween is a fast, efficient, fully type-safe object-oriented animation engine for Unity, optimized for C# users, free and open-source, with tons of advanced features

DOTween is a fast, efficient, fully type-safe object-oriented animation engine for Unity, optimized for C# users, free and open-source, with tons of advanced features

This is the most flexible way of tweening and allows you to tween almost any value, either public or private, static or dynamic (just so you know, the shortcuts way actually uses the generic way in the background).

static DOTween.To(getter, setter, to, float duration)

Changes the given property from its current value to the given one.
getter A delegate that returns the value of the property to tween. Can be written as a lambda like this: ()=> myValue
where myValue is the name of the property to tween.
setter A delegate that sets the value of the property to tween. Can be written as a lambda like this: x=> myValue = x
where myValue is the name of the property to tween.
to The end value to reach.
duration The duration of the tween.

Examples

// Tween a Vector3 called myVector to 3,4,8 in 1 second
DOTween.To(()=> myVector, x=> myVector = x, new Vector3(3,4,8), 1);
// Tween a float called myFloat to 52 in 1 second
DOTween.To(()=> myFloat, x=> myFloat = x, 52, 1);
Did you like the article? Share with friends:
Автор snezhok_13
Writes about gamedev. Graphics programmer on AAA projects.

Leave a Reply

Your email address will not be published. Required fields are marked *