2016-01-25 50 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。 我希望有帮助!