Changing the length of a line renderer using DOTween

2.5k Views Asked by At

I am trying to change the length of my line renderer over time using DOTween.

LineRenderer myLineRenderer = GetComponent<LineRenderer>();
myLineRenderer.SetPosition(1, new Vector3(x, 0, 0));

This code snippet changes the position of myLineRenderer to x. How can I use DOTween to set the position gradually to x over 1 second?

2

There are 2 best solutions below

2
On BEST ANSWER

Why not just tween it yourself?

float x = 0f;

IEnumerator TweenLinerenderer()
{
    while(x <= 1f)
    {
        myLineRenderer.SetPosition(1, new Vector3(x, 0, 0));
        x += Time.deltaTime;
        yield return null;
    }
    x = 0f;
}
0
On
LineRenderer l = GetComponent<LineRenderer>();
DOTween.To(() => l.GetPosition(lineRenderPoint), (x) => l.SetPosition(lineRenderPoint, x), new Vector3(0, 0, 10), 10).Play();

Where lineRenderPoint is the point you want to move.