using UnityEngine;
using System.Collections;
public class Line : MonoBehaviour
{
public Material mat;
public Color color = Color.red;
public Vector3 pos1;
public Vector3 pos2;
void Start()
{
mat.color = color;
}
void Update()
{
if (Input.GetMouseButtonDown(0))
{
pos1 = Input.mousePosition;
}
if (Input.GetMouseButton(0))
{
pos2 = Input.mousePosition;
}
}
void OnPostRender()
{
GL.PushMatrix();
mat.SetPass(0);
GL.LoadOrtho();
GL.Begin(GL.LINES);
GL.Color(color);
GL.Vertex3(pos1.x / Screen.width, pos1.y / Screen.height, 0);
GL.Vertex3(pos2.x / Screen.width, pos1.y / Screen.height, 0);
GL.Vertex3(pos2.x / Screen.width, pos1.y / Screen.height, 0);
GL.Vertex3(pos2.x / Screen.width, pos2.y / Screen.height, 0);
GL.Vertex3(pos2.x / Screen.width, pos2.y / Screen.height, 0);
GL.Vertex3(pos1.x / Screen.width, pos2.y / Screen.height, 0);
GL.Vertex3(pos1.x / Screen.width, pos2.y / Screen.height, 0);
GL.Vertex3(pos1.x / Screen.width, pos1.y / Screen.height, 0);
GL.End();
GL.PopMatrix();
}
}
在unity裏用GL畫線框
最近由於閒來無事,無意中看到vectrosity這個畫線插件,就想研究一下,下載下來之後發現導入到unity裏之後出現錯誤,由於自己是蠢新所以改了一通也沒改對,所以就放棄了,大家需要插件的話待會我會上下載鏈接,自己可以試試,我的版本是5.2.2的,在找到http://blog.csdn.net/awnuxcvbn/article/details/17279837這個利用GL畫線的,但是感覺效果不好,所以自己修改了一下,改成了畫線框的,其實就是確定了四個點而已,而且修改成了與鼠標同步畫線的效果,大家有興趣的可以看看,共同進步···········
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.