Animating Numbers

Number animation scripting example.

Float, Int, and Double are supported animatable number types. Although, for unsupported types, you can just use implicit or explicit type conversion.

It's required to pass a setter that will set the value of the number that you want animated with each update.

Animating a Float

public class NumberAnimationTest : MonoBehaviour
{
    private float number;

    void Start()
    {
        // Animate number from 0 to 100 in 1 second
        AnimationCreator.FloatAnimation(0, 100, (x) => number = x, 1);
    }

    private void Update()
    {
        Debug.Log(number);
    }
}

Type Conversion

We can use the above example and slightly alter it to animate a numeric type of our choice.

For example, here's how we can animate a ulong instead of a float:

public class NumberAnimationTest : MonoBehaviour
{
    private ulong number;

    void Start()
    {
        // Animate number from 0 to 100 in 1 second
        AnimationCreator.FloatAnimation(0, 100, (x) => number = (ulong)x, 1);
    }

    private void Update()
    {
        Debug.Log(number);
    }
}

Animating a Double

Use AnimationCreator.DoubleAnimation to animate a double.

// Animate number from 0 to 100 in 1 second
AnimationCreator.DoubleAnimation(0, 100, (x) => number = x, 1);

Animating an Int

Use AnimationCreator.IntAnimation to animate an int.

// Animate number from 0 to 100 in 1 second
AnimationCreator.IntAnimation(0, 100, (x) => number = x, 1);

Last updated