2016-01-25 49 views
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); 
} 

和截圖。 統一遊戲窗口: Game

構建窗口 Build

+0

您是否檢查了項目圖形設置以確保着色器(來自其他問題的答案)包含在內? – 31eee384

+0

您是否沿着使用舊版本腳本的方式創建了新場景?你可能沒有構建你想要的場景。 – Draco18s

+0

@ 31eee384我不使用Material mat = new Material(Shader.Find(「Unlit/Texture」));我使用: gridLineRenderer.material.color = Color.black; –

回答

1

試試這個:

gridLineRenderer.material.SetColor ("_TintColor", Color.black); 

,而不是當前行您使用的是改變材料的顏色。 另請嘗試使用不同的着色器。

material.color = Color.black;基本上是material.SetColor ("_Color", Color.black)的簡寫。一些着色器使用_TintColor而不是_Color。 我希望有幫助!