unity GL库的坐标左下角(0,0),右上角(1,1)
示例代码如下:
- public Material material;//材质,一定要有
- void OnPostRender ()
- {
- if (!material) {
- Debug.LogError ("请给材质赋值");
- return;
- }
- material.SetPass (0);
- GL.LoadOrtho ();//绘制对象显示在平面上
- GL.Begin (GL.LINES);//画的是线段
- DrawLine (0, 0, 200, 200);
- GL.End ();
- }
- void DrawLine (float x1, float y1, float x2, float y2)
- {
- GL.Vertex (new Vector3 (x1 / Screen.width, y1 / Screen.height, 0));
- GL.Vertex (new Vector3 (x2 / Screen.width, y2 / Screen.height, 0));
- }
这个脚本一定要挂载在摄像机上。