Just another line renderer question. Line renderer vector positions in an array of game objects. My line only draws between 2 positions?
I'm attempting to get a line renderer to draw a line between a few dynamically moving objects in my scene. I have managed to create an array and have it iterate through the for loop ok as it displays the correct index numbers in the console. The line is also been drawn between object zero and object one in the array/loop. However once it reaches the second point it just stops and the line doesn't continue. Im not a programmer but have a basic understanding so a code check and an explaination and a solution would be appreciated. Heres the code I have to far... The objects used in the array are currently simple static cubes. I can move the first 2 around and the line follows so far. Number 3 is not doing anything apart from updating vector positions in the console.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class linefollow : MonoBehaviour {
private LineRenderer linerenderer;
public Transform[] vectorpoints;
// Use this for initialization
void Start () {
linerenderer = GetComponent<LineRenderer>();
linerenderer.SetWidth(.45f, .45f);
}
// Update is called once per frame
void Update () {
var points = new Vector3[vectorpoints.Length];
for(int i = 0; i < vectorpoints.Length; i++){
points[i] = vectorpoints[i].position;
Debug.Log (points[i]);
}
linerenderer.SetPositions(points);
}
}
When is rendered, what you see in the inspector? Paste it..
Answer by danosbe · Jul 05, 2018 at 08:56 AM
Not sure what you mean? but here's the log showing the vector co-ordinates for the cubes in the array. The inspector just has the line renderer and the script posted above attached to it.
Figured it out, the line renderer itself had to have 3 Elements (or the same as however many items in my array I need) set in the inspector.