using System.Collections.Generic;
using UnityEngine;
public class huatu : MonoBehaviour
{
private GameObject Go;
private LineRenderer line;
private int i;
public GameObject go;
int lint = 0;
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonDown(0))
{
//克隆出Go的个数
lint++;
//克隆一个带有LineRender的物体
Go = (GameObject)Instantiate(go, go.transform.position, transform.rotation);
//名字按个数命名
Go.name = lint.ToString();
//获取LineRender组件
line = Go.GetComponent<LineRenderer>();
//颜色
line.SetColors(Color.blue, Color.red);
//宽度
line.SetWidth(0.2f, 0.1f);
i = 0;
// print(lr.Count + "kjdsakljdlkjakl");
}
if (Input.GetMouseButton(0))
{
// print(i);
i++;
//设置顶点数
line.SetVertexCount(i);
print(line.positionCount);
//设置顶点位置
line.SetPosition(i - 1, Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 15)));
}
if (Input.GetMouseButton(1))
{
//获取到最后一个
int o = GameObject.Find(lint.ToString()).GetComponent<LineRenderer>().positionCount;
print("kjsahdkjhask" + o);
o--;
//删除顶点个数
GameObject.Find(lint.ToString()).GetComponent<LineRenderer>(). SetVertexCount(o);
if (o<=0)
{
//如果顶点个数为0删除此物体
Destroy(GameObject.Find(lint.ToString()));
lint--;
print(lint);
}
}
}
}