0
\$\begingroup\$

I'm drawing a line with a LineRenderer. It works, but now I would like it the line to be drawn gradually, instead of appearing all at once.

How can I modify my code to achieve this?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class LineController : MonoBehaviour
{

    private LineRenderer Ir;
    private Transform [] points;


    private void Awake(){

        Ir = GetComponent <LineRenderer>();
    }
    
    public void SetUpLine (Transform[] points){
        Ir.positionCount = points.Length;
        this.points = points;
    }

    private void Update (){
        for (int i = 0; i < points.Length; i++) {
            Ir.SetPosition(i, points[i].position);
            Debug.Log (points[i].position);
        }
        
    }
}
\$\endgroup\$
1
  • 1
    \$\begingroup\$ Do you mean, have the line extend from the point 0, passing through all the other points, arriving at the final one, over time? Like how some games represent beams of light bouncing? \$\endgroup\$
    – Weckar E.
    Commented Nov 29, 2020 at 9:08

1 Answer 1

0
\$\begingroup\$

You can use MathF.lerp. You would draw it from the start position to finish position by lerping it between them based on the elapsed time.

\$\endgroup\$
1
  • \$\begingroup\$ This answer would be better if it included an example of how to do this. \$\endgroup\$
    – DMGregory
    Commented Jan 1, 2021 at 14:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .