Reputation: 437
I'm working in Unity and I'm create LineRenderers as children of a GameObject named "out100". I can move this GameObject with a mouse scroll click, rotate it with a right click etc... But it's only the GameObject "out100" that moves and not the LineRenderers.
How can I adjust the code below to get the LineRenderers to move with the GameObject "out100"?
Code:
foreach (KeyValuePair<string, List<Vector3>> sl in d)
{
Color c1 = Color.yellow;
Color c2 = Color.red;
GameObject lines = new GameObject ();
lines.name = "lines" + sl.Key;
lines.AddComponent<LineRenderer> ();
lines.transform.SetParent (GameObject.Find ("out100").transform);
LineRenderer lineRenderer = lines.GetComponent<LineRenderer> ();
lineRenderer.material = new Material (Shader.Find ("Particles/Additive"));
lineRenderer.widthMultiplier = 0.2f;
lineRenderer.positionCount = sl.Value.Count;
float alpha = 1.0f;
Gradient gradient = new Gradient ();
gradient.SetKeys
(
new GradientColorKey[] { new GradientColorKey (c1, 0.0f), new GradientColorKey (c2, 1.0f) },
new GradientAlphaKey[] { new GradientAlphaKey (alpha, 0.0f), new GradientAlphaKey (alpha, 1.0f) }
);
lineRenderer.colorGradient = gradient;
lineRenderer.GetComponent<LineRenderer> ().SetPositions (sl.Value.ToArray());
}
Upvotes: 4
Views: 5066