纳金网

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

作者: 狂风大尉    时间: 2014-6-27 00:09
标题: 画直线和斜线
  1. var mat : Material;
  2. private var startVertex : Vector3;
  3. private var mousePos : Vector3;
  4. startVertex = Vector3(0,0,0);

  5. function Start () {
  6.         print("start");
  7. }

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



  15. function OnPostRender() {
  16.                 if (!mat) {
  17.                         Debug.LogError("Please Assign a material on the inspector");
  18.                         return;
  19.                 }
  20.                 GL.PushMatrix();
  21.                 mat.SetPass(0);
  22.                 GL.LoadOrtho();
  23.                 GL.Begin(GL.LINES);
  24.                 GL.Color(Color.red);
  25.                 GL.Vertex(startVertex);
  26.                 GL.Vertex(Vector3(mousePos.x/Screen.width, mousePos.y/Screen.height, 0));
  27.                 GL.End();
  28.                 GL.PopMatrix();
  29. }
复制代码

作者: hyui    时间: 2014-6-27 00:38
Good to know !
作者: wucnj    时间: 2014-6-27 11:10
感谢分享!!!




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