我正在进行我的第一场2D比赛.
我在生成游戏领域时遇到问题.
我需要做3件事.
我在生成游戏领域时遇到问题.
我需要做3件事.
>用方形瓷砖填充场地(完成)
>在每个瓷砖上显示随机数(完成)
>显示网格线(问题在这里)
要创建我的主板,我使用附加到主相机的脚本.
这是我使用的功能:
void BoardSetup() { board = new GameObject("Board"); boardHolder = board.transform; for (int x = 0; x < columns; x++) { for (int y = 0; y < rows; y++) { GameObject toInstantiateBackground = sNowTile; GameObject backgroundInstance = Instantiate(toInstantiateBackground,new Vector3(x,y,0f),Quaternion.identity) as GameObject; backgroundInstance.transform.SetParent(boardHolder); AddRandomNumber(backgroundInstance,x,y); } } float step = sNowTile.GetComponent<SpriteRenderer>().bounds.max[0] - sNowTile.GetComponent<SpriteRenderer>().bounds.min[0]; CreateGrid(new Vector3(0,0),new Vector3(rows-1,columns-1,step); }
这是我的CreateGrid块:
void CreateLineMaterial() { if (!lineMaterial) { lineMaterial = new Material("Shader \"Lines/Colored Blended\" {" + "SubShader { Pass { " + " Blend SrcAlpha OneMinusSrcAlpha " + " ZWrite Off Cull Off Fog { Mode Off } " + " BindChannels {" + " Bind \"vertex\",vertex Bind \"color\",color }" + "} } }"); lineMaterial.hideFlags = HideFlags.HideAndDontSave; lineMaterial.shader.hideFlags = HideFlags.HideAndDontSave; } } private void CreateGrid(Vector3 start,Vector3 stop,float step) { CreateLineMaterial(); // set the current material lineMaterial.SetPass(0); GL.Begin(GL.LInes); GL.Color(gridColor); // Vertical lines for (float x = start[0]; x <= stop[0]; x += step) { GL.Vertex3(x,0f,0f); GL.Vertex3(x,stop[1],0f); } // Horizontal lines for (float y = start[0]; y <= stop[1]; y += step) { GL.Vertex3(0f,0f); GL.Vertex3(stop[0],0f); } GL.End(); }
我试图只运行CreateGrid()但在这种情况下我只看到黑屏.
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。