- Home /
Question by
ratchetunity · May 14, 2019 at 04:25 PM ·
shadercolorlinerenderercustom shader
Change linerenderer color to custom shader's color
Hi!
I have a custom shader and I want to change the linerenderer's color to the shader of the sphere at runtime, but I don't know how to do it. This is my code:
[SerializeField] GameObject sphere;
[SerializeField] GameObject link;
private LineRenderer lineRenderer;
private void Awake () {
lineRenderer = link.GetComponent<LineRenderer>();
lineRenderer.positionCount = 2;
}
private void Start () {
CreateColor();
}
private void CreateColor()
{
lineRenderer.startColor = sphere.GetComponent<Renderer>().material.color;
lineRenderer.endColor = sphere.GetComponent<Renderer>().material.color;
Instantiate(link, Vector3.zero, Quaternion.identity, sphere.transform);
}
Comment
Answer by Zaeran · May 15, 2019 at 12:03 AM
You need to apply a material to the LineRenderer and set the colour of that material, instead of setting the startColor and endColor variables like so:
lineRenderer.GetComponent<Renderer>().material.color = sphere.GetComponent<Renderer>().material.color
Hello @Zaeran ! Thanks foryour answers, but it doesn't work. I'm using a custom shader for the sphere material.
Your answer
Follow this Question
Related Questions
Creating a line between different colors? 0 Answers
ShaderGraph Material Color change. 0 Answers
LineRenderer renders the wrong color 3 Answers