- Home /
Is there a technique to change the color of Line Renderer between two points?
I'm working with Line Renderer and I want to change the color of the material between two specific points of the line via script. The goal is to make long segments of the line darker.
I would like to know if you have a technique to do that. Thank you.
Answer by Kiloblargh · Aug 02, 2013 at 06:54 PM
You mean, you were trying to work with the Line Renderer, until you realized its script interface was totally inadequate for what you wanted to achieve, and now you're starting work on a custom procedural mesh generation script to replace it.
I speak from experience, having wanted to change colors of the TrailRenderer at runtime until I realized you just... plain... can't. The visual effects Unity comes with are great when what you need is exactly what it already does; if not, forget trying to adapt or modify it, you are going to have to go in and get your mesh.vertices dirty.
Yep. So, what I understand from your advice is that I should forget about the default line renderer. I like your answer. So the solution is to do a custom procedural mesh generation.
Answer by DaveA · Aug 02, 2013 at 04:49 PM
Did you not read this? http://docs.unity3d.com/Documentation/ScriptReference/LineRenderer.SetColors.html
So, in hopes that I get upvoted to zero, what if you made your line segements, instead of just 2 points, out of say, 4 points (all co-linear), and set the colors of each segment with the desired colors. If you just used 3 points, for example, you could set the middle point at the 10% distance from the first, and then 10 percent would fade from first to middle color, the last 90% from the middle color to the end color. Use as many segments as you need.
To be fair, that says the color at the start and end, which suggests the whole length of the line will fade between the first color and the second. I think what the OP wants to do is to have each segment of the line fade between two colors
SetColors is for the entire line and not just a segment. This goes with what Xtro suggested.
Answer by Xtro · Aug 02, 2013 at 04:47 PM
You can draw multiple lines for different segments with different materials. But I doubt if you'll like this idea.
In fact, it would be the ad hoc solution, but I think there will be performance issue. A line can be over 2000 segments long. That's a lot (especially for a mobile game).
Answer by jfa257 · Mar 24, 2021 at 06:49 PM
I think drawing multiple lines, can be a solution, since basically the line renderer does this for every segment. They put up a quad, and then assign the material to it. So it would give you more control without sacrificing performance. Actually, I think it would be better since leaving the line renderer object to handle all the segments, can be more heavy.
Your answer
![](https://koobas.hobune.stream/wayback/20220613111222im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Material doesn't have a color property '_Color' 4 Answers
Changing two different objects renderer colour 1 Answer
Changing a materials color in C# 2 Answers
I want each face of an object to be a different color 1 Answer
Problem getting prefab color 0 Answers