- Home /
GL.LINES cannot switch colors
Currently I am using GL.Lines to create a kind of sonar vision. Unfortunately I can't seem to change the color of the lines, I think I am doing something wrong here but I don't know where. Having a single red sonar works, but when having a red and white one at the same time, all the sonar turns to white.
GL.Begin(GL.LINES);
for (int ii = 0; ii < lines.Count; ii++) {
LineOfSight l = lines[ii];
l.lineMat.SetPass(0);
GL.Color(l.colour);
for (int i = l.vertices.Count - 1; i > 0; i--) {
GL.Vertex(l.vertices[i - 1]);
GL.Vertex(l.vertices[i]);
}
}
Debug.Log(lines.Count);
GL.End();
Answer by Bunny83 · Jun 18, 2016 at 10:07 AM
Well, what kind of material are you using? What shader? You need a shader that uses vertex colors and no lighting.
Also i don't think you should or can change the pass in between a GL.Begin and it's corresponding GL.End. A Begin and End pair represent a drawcall which is carried out with the same material / shader. If the material is always the same and only the vertex color is different, you should place your SetPass call in front of the GL.Begin and only change the vertex color with GL.Color just like you do at the moment.
As i said you need a material that uses vertex colors.
Worked like a charm! Used this http://wiki.unity3d.com/index.php/VertexColorUnlit