1
我正在Unity中進行我的第一個遊戲。我試圖在我的遊戲領域畫線。 我有一個線顏色的問題,但現在它解決了(How to set correct color to lines?)構建不正確的線條顏色
但是,當我建立我的遊戲,並運行它,我再次看到粉紅色的林。
請注意,在Unity編輯器的遊戲窗口中一切正常。
我的代碼:
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.material.color = Color.black;
gridLineRenderer.SetVertexCount(2);
gridLineRenderer.SetWidth(0.01f, 0.01f);
gridLineRenderer.SetColors(Color.black, Color.black);
gridLineRenderer.SetPosition(0, start);
gridLineRenderer.SetPosition(1, stop);
}
您是否檢查了項目圖形設置以確保着色器(來自其他問題的答案)包含在內? – 31eee384
您是否沿着使用舊版本腳本的方式創建了新場景?你可能沒有構建你想要的場景。 – Draco18s
@ 31eee384我不使用Material mat = new Material(Shader.Find(「Unlit/Texture」));我使用: gridLineRenderer.material.color = Color.black; –