纳金网

标题: 画直线和斜线的代码 [打印本页]

作者: 王者再临    时间: 2014-11-30 23:51
标题: 画直线和斜线的代码
var mat : Material;
private var startVertex : Vector3;
private var mousePos : Vector3;
startVertex = Vector3(0,0,0);

function Start () {
        print("start");
}

function Update () {
        mousePos = Input.mousePosition;
                // Press space to update startVertex
                if(Input.GetKeyDown(KeyCode.Space)){
                        startVertex = Vector3(mousePos.x/Screen.width, mousePos.y/Screen.height, 0);
                }
}



function OnPostRender() {
                if (!mat) {
                        Debug.LogError("Please Assign a material on the inspector");
                        return;
                }
                GL.PushMatrix();
                mat.SetPass(0);
                GL.LoadOrtho();
                GL.Begin(GL.LINES);
                GL.Color(Color.red);
                GL.Vertex(startVertex);
                GL.Vertex(Vector3(mousePos.x/Screen.width, mousePos.y/Screen.height, 0));
                GL.End();
                GL.PopMatrix();
}






欢迎光临 纳金网 (http://go.narkii.com/club/) Powered by Discuz! X2.5