- Home /
Question by
zardini123 · Jan 11, 2016 at 12:59 AM ·
errorline rendererinstances
LineRenderer.SetPositions Error
I am trying to set the positions of a line renderer using SetPositions, but I get this error when calling SetPositions on a LineRenderer instance:
Type `UnityEngine.LineRenderer' does not contain a definition for `SetPositions' and no extension method `SetPositions' of type `UnityEngine.LineRenderer' could be found (are you missing a using directive or an assembly reference?)
This is the code the error is from:
lineRendererGM = new GameObject("Line");
lineRendererGM.AddComponent<LineRenderer>();
lineRendererGM.GetComponent<LineRenderer>().SetVertexCount(3);
lineRendererGM.GetComponent<LineRenderer>().useWorldSpace = true;
Vector3[] points = new Vector3[3];
points[0] = theMesh.vertices[theMesh.triangles[t]];
points[1] = theMesh.vertices[theMesh.triangles[t + 1]];
points[2] = theMesh.vertices[theMesh.triangles[t + 2]];
for (int i = 0; i < points.Length; i++) {
points[i] = transform.TransformDirection(points[i]);
}
lineRendererGM.GetComponent<LineRenderer>().SetPositions(points);
Comment
Answer by JoshuaMcKenzie · Jan 11, 2016 at 05:36 AM
I can't say if this function only exists in the current version of unity but it doesn't exist in the version of Unity that my group are sticking to for our game (5.1.1). The Documentation fails to specify this.
However I do use SetPosition() with no problems when I render my chain lightning in my game. I build the vector point and increment the VertexCount and SetPosition for each iteration in a loop.