Тема: 3d Floor Plan
Показать сообщение отдельно
Старый 29.02.2012, 13:31   #17
Georg Gukov
AnyKey`щик
 
Регистрация: 20.02.2012
Сообщений: 11
Написано 0 полезных сообщений
(для 0 пользователей)
Ответ: 3d Floor Plan

Как отредактировать этот скрипт так чтобы он рисовал не линию а прямоугольник
using UnityEngine;
using System.Collections.Generic;
public class example : MonoBehaviour {

struct line
{
public Vector3 start;
public Vector3 end;
}
public Material mat;
private Vector3 mousePos;
private bool startDraw;
private List<line> lines;
private line currentLine;
void Start() {
lines = new List<line>();
startDraw = false;
}
void Update() {
mousePos = Input.mousePosition;
if (Input.GetKeyDown(KeyCode.Space) && !startDraw)
{
currentLine.start = new Vector3(mousePos.x / Screen.width, mousePos.y / Screen.height, 0);
startDraw = true;
}else if (Input.GetKeyDown(KeyCode.Space) && startDraw)
{
currentLine.end = new Vector3(mousePos.x / Screen.width, mousePos.y / Screen.height, 0);
lines.Add(currentLine);
startDraw = false;
}

}
void OnPostRender() {
if (!mat) {
Debug.LogError("Please Assign a material on the inspector");
return;
}
GL.PushMatrix();
mat.SetPass(0);
GL.LoadOrtho();

foreach(line l in lines)
{
GL.Begin(GL.LINES);
GL.Color(Color.red);
GL.Vertex(l.start);
GL.Vertex(l.end);
GL.End();
}

if(startDraw)
{
GL.Begin(GL.LINES);
GL.Color(Color.yellow);
GL.Vertex(currentLine.start);
GL.Vertex(new Vector3(mousePos.x / Screen.width, mousePos.y / Screen.height, 0));
GL.End();
}
GL.PopMatrix();
}
}
(Offline)
 
Ответить с цитированием