Hi All,
I’m trying to paint lines to draw a distance between to nodes. My problem is that those lines are created using lineRenderer as an object. So I have to create and erase them to update their position, at the same time they are created dynamically, if only two nodes are close only one line is painted but if 1000 nodes are close then 500 lines are created.
How to do this in a simple way without adding the object in unity engine? for example in OpenGL you just draw a line using a vertex with both positions and they are not really expensive. It is clear the question?
Thanks for the help
David
public void PaintDistance ()
{
foreach (Transform child in transform) {
if (child.gameObject.name.Length > 5) {
if (child.gameObject.name == "distanceLine")
Destroy (child.gameObject);
}
}
for (int i = 1; i < gm.nodeCount; i++) {
for (int j = i+1; j < gm.nodeCount; j++) {
if (gm.Nodes [i] != gm.Nodes [j]) {
Vector3 force = gm.Nodes [i].newPosition - gm.Nodes [j].newPosition;
float distance = force.magnitude;
if (distance < 10.0f) {
LineRenderer d_line = new GameObject ("distanceLine").AddComponent ("LineRenderer") as LineRenderer;
d_line.renderer.castShadows = true;
d_line.renderer.receiveShadows = true;
d_line.transform.parent = gameObject.transform;
d_line.transform.localPosition = Vector3.zero;
d_line.material = new Material (Shader.Find ("Particles/Alpha Blended"));
d_line.SetWidth (0.1f, 0.1f);
d_line.useWorldSpace = true;
d_line.SetColors (c2, c2);
d_line.SetVertexCount (2);
d_line.SetPosition (0, gm.Nodes [i].newPosition);
d_line.SetPosition (1, gm.Nodes [j].newPosition);
}
}
}
}
}