发布时间:2023-05-02 11:00
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();
}
}