I am trying to just add a material to the line that is rendered but I am only seeing a magenta line. The material is in the project and so it is not missing, but yet the line renderer just seems to ignore the material I have assigned to it. Code show below;
var startWidth = 0.05;
var endWidth = 0.05;
var aMaterial : Material;
private var line : LineRenderer;
function Start ()
{
line = this.gameObject.AddComponent(LineRenderer);
//line.material = new Material (Shader.Find("Particles/Additive"));
line.SetWidth(startWidth, endWidth);
line.SetVertexCount(2);
line.material = aMaterial;
line.renderer.enabled = true;
}
Any help would be greatly appreciated.
I know this is an old post but might help someone else. To get the built in start / end colors this is what I did. Not that this is a very quick solution.
- Create an Empty object
- Add component > Effects> Line Renderer
- Create a material
- Change the Shader Particles Alpha Blend. Particles>Alpha Blend.
- Add the Material to Line Renderer Materials
Most of the particle shaders will work but Alpha blend gave me the best look. I didn’t have to do any coding for this part. Only code I had to display the line was setting the positions.
///------------------------------
LineRenderer lr;
Void Start()
{
lr = GetComponent<LineRenderer>();
lr.SetPositions(points); //points=an array of points(Vector3)
}
///------------------------------------------
First of all, this line = this.gameObject.AddComponent(LineRenderer);
should be this line = this.gameObject.AddComponent();
. Argument of the AddComponent should be empty, only the type assignment operators <> to define its type. But that’s not going to solve your problem.
I’ve been stuck with the same problem but luckily I found a solution. You’ll need a simple, constant, self-illuminating material (so NOT one of the Particle materials) and assign that one to the lineRenderer (this works best in the editor).
-
Add a LineRenderer component to the gameobject via the Unity Editor
-
Change this: line = this.gameObject.AddComponent(LineRenderer);
to this:
line = gameObject.GetComponent();
-
Make a new material with a Self-Illumin/Diffuse and assign a color to it (no texture!)
-
Assign the new material to the LineRenderer component in the Unity Editor
This worked for me, hopefully you’ll be helped with this too 
Self-Illumin/Diffuse didn’t work well for me. This 6 line shader taken from another similar question did tho: Shader needed for gradients using a LineRenderer - Questions & Answers - Unity Discussions
Shader "Vertex Colors" {
Subshader {
BindChannels {
Bind "vertex", vertex
Bind "color", color
}
Pass {}
}
}