1-创建空物体添加上line render组件
2-代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class lin : MonoBehaviour
{
private LineRenderer Ld; //线组件
private Vector3 pos; // 线的点位置
public float Ldwith; // 线宽度
public Material mat; // 设置材质
private void Update()
{
if (Input.GetMouseButtonDown(0))
{
GameObject obj = new GameObject();
Ld = obj.AddComponent<LineRenderer>(); // 添加空物体且添加组件
Ld.loop = false; //关闭自动连接
Ld.startWidth = Ldwith;
Ld.endWidth = Ldwith; // 线宽度
Ld.positionCount = 0;// 默认点为0
Ld.material = mat;// 线材质
}
if (Input.GetMouseButton(0))
{
Ld.positionCount += 1;//点增加
po