核心脚本:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MouseLine : MonoBehaviour
{
private LineRenderer currentLine;
public Material LineMaterial;
private PublicNeed publicNeed;
private List<Vector3> positions = new List<Vector3>();
private bool isMouseDown = false;
private Vector3 lastMousePosition;
private float lineAdd = 0.1f;
void Start()
{
publicNeed = GetComponent<PublicNeed>();
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonDown(0))
{
GameObject go = new GameObject();
go.transform.SetParent(this.transform);
currentLine = go.AddComponent<LineRenderer>();