//have to add a new game object per line renderer
LineRenderer lineRenderer = new GameObject().AddComponent<LineRenderer>();
The other issue is that if your lines are using a shader that isn't referenced anywhere else in your scene, the Unity Editor won't include them in your package and the lines won't render in a build project although they will work in the editor.
// force the shader to be copied into the resource folder using
// Edit->ProjectSettings->Graphics->Always Included Shaders
Material whiteDiffuseMat = new Material(Shader.Find("Unlit/Color"));
lineRenderer.material = whiteDiffuseMat;
Not completely horrible but still, hoops to be jumped through...
using UnityEngine;
using System.Collections;
public class basicRender : MonoBehaviour {
void RenderCircle(Vector3 pos, float rad, Color col)
{
float angle = 0.0f;
int segments = 128;
//have to add a new game object per line renderer
LineRenderer lineRenderer = new GameObject().AddComponent<LineRenderer>();
// force the shader to be copied into the resource folder using Edit->ProjectSettings->Graphics->Always Included Shaders
Material whiteDiffuseMat = new Material(Shader.Find("Unlit/Color"));
lineRenderer.material = whiteDiffuseMat;
lineRenderer.SetColors(new Color(1.0f,1.0f,1.0f,1.0f), new Color(1.0f,1.0f,1.0f,1.0f));
lineRenderer.SetWidth(0.02F, 0.02F);
lineRenderer.SetVertexCount(1+segments);
for (int i = 0; i < (segments + 1); i++)
{
Vector3 p = new Vector3();
p.x = pos.x + (Mathf.Sin (Mathf.Deg2Rad * angle)*rad);
p.y = pos.y + (Mathf.Cos (Mathf.Deg2Rad * angle)*rad);
p.z = pos.z;
lineRenderer.SetPosition (i,p);
angle += (360.0f / segments);
}
}
// Use this for initialization
void Start ()
{
float r = 0.6f;
for (int i = 0; i<20; i++)
{
RenderCircle(new Vector3(0.0f,0.0f,0.0f),r,new Color(1.0f,1.0f,1.0f,1.0f));
r+=0.6f;
}
}
// Update is called once per frame
void Update ()
{
if (Input.GetKeyDown(KeyCode.Escape)) Application.Quit();
}
private void OnDestroy()
{
Destroy(this.GetComponent<Renderer>().material);
}
}