How to render a LineRenderer through multiple points?

Hello i am having a little trouble trying to render Lines through multiple points but the only thing i’m getting is whats in the picture, its only the start point to 0,0,0 anyone know how to fix this?

Here is my code so you know what i have done.

using UnityEngine;
using System.Collections;

[RequireComponent(typeof(LineRenderer))]
public class Lines : MonoBehaviour {

    LineRenderer lineRenderer;
    public Transform[] points;

	void Update () {
        lineRenderer = GetComponent<LineRenderer>();
        for (int i = 0; i < points.Length; i++)
            lineRenderer.SetPosition(0, points[0].position);
	}
}

You have 3 problems here.

  1. You are not using the i variable made in the loop, so you are only using the first position.
    To fix this replace lineRenderer.SetPosition(0, points[0].position); with lineRenderer.SetPosition(0, points*.position);*
    2. You are using SetPosition instead of SetPositions
    3. doing this whole computation in the update function is really inefficient.
    So this is what I recommend you do:
    Using System.Collections.Generic;

[RequireComponent(typeof(LineRenderer))]
public class Lines : MonoBehaviour {

LineRenderer lineRenderer;
public Transform[] points;
private Vector3[] positionsOfPoints;

void Start(){
lineRenderer = GetComponent();
UpdateLine(); // this can be called in update if your positions aren’t static
}

void UpdateLine()
{
List temp = new List():
foreach(Transform t in points)
{
temp.Add(t.position);
}

positionsOfPoints = temp.ToArray();
lineRenderer.SetVertexCount(positionsOfPoints.Length); // add this
lineRenderer.SetPositions(positionsOfPoints);
}
}
I haven’t tested this yet but it seems correct. :slight_smile:

OK i have fixed it here is the code.

using UnityEngine;
using System.Collections;

[RequireComponent(typeof(LineRenderer))]
public class Lines : MonoBehaviour {

    LineRenderer lineRenderer;
    public Transform[] points;
    private Vector3[] vP;
    int seg = 20;
    void Start()
    {
        lineRenderer = GetComponent<LineRenderer>();
        Line();
    }
	void Line () {
        seg = points.Length;
        vP = new Vector3[points.Length];
        for (int i = 0; i < points.Length; i++)
        {
            vP _= points*.position;*_

}
for (int i = 0; i < seg; i++)
{
float t = i / (float)seg;
lineRenderer.SetVertexCount(seg);
lineRenderer.SetPositions(vP);
}

* }*
}

You’re not using your iteration index in your for loop. Change points[0].position to points*.position.*