D
D
Dmitry Demidov2015-12-22 23:42:18
Game development
Dmitry Demidov, 2015-12-22 23:42:18

How to draw lines of the desired color?

Hello!
Figured out how to draw lines on the playing field.
I do it like this:

private void DrawLine(Vector3 start,  Vector3 stop, GameObject template)
    {
        GameObject toInstiateGridLine = template;
        GameObject gridLineInstance = Instantiate(toInstiateGridLine, start, Quaternion.identity) as GameObject;
        LineRenderer gridLineRenderer = gridLineInstance.GetComponent<LineRenderer>();
        gridLineRenderer.SetVertexCount(2);
        gridLineRenderer.SetWidth(0.01f, 0.01f);
        gridLineRenderer.SetColors(Color.black, Color.black);
        gridLineRenderer.SetPosition(0, start);
        gridLineRenderer.SetPosition(1, stop);
    }

Lines are drawn but pink (I'm expecting black). It looks like this:
96b057c694544defa836826c4b4ebc45.PNG
Here are the settings of the LineRenderer component created at runtime:
819cc2fd42344a3d9e75769719dd2bf8.PNG
Actually the question. How to make lines black?
Question on SOF.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Demidov, 2015-12-23
@ptitca_zu

The problem was that the LineRenderer didn't have a material.
I solved it with one line:
When accessing the material property, if it does not exist, a default material is created.
It is also possible to create the material yourself and attach it to the component (see SOF answer).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question