using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DrawLine : MonoBehaviour
{
private LineRenderer lineRenderer;
private Vector3 position;
private int LengthOfLineRenderer=0;
private int index=0;
private Mesh meshTest;
private void Start()
{
lineRenderer = gameObject.GetComponent<LineRenderer>();
lineRenderer.startColor = Color.red;
lineRenderer.endColor = Color.yellow;
lineRenderer.startWidth = 0.05f;
lineRenderer.endWidth = 0.05f;
}
private void Update()
{
lineRenderer = GetComponent<LineRenderer>();
if (Input.GetMouseButtonDown(0))
{
position = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x,Input.mousePosition.y,1f));
LengthOfLineRenderer++;
lineRenderer.positionCount = LengthOfLineRenderer;
//lineRenderer.SetVertexCount(LengthOfLineRenderer);//设置线条段数
}
while (index<LengthOfLineRenderer)
{
lineRenderer.SetPosition(index,position);
//lineRenderer.BakeMesh(meshTest);
index++;
}
}
private void OnGUI()
{
GUILayout.Label("当前鼠标X轴的位置"+Input.mousePosition.x);
GUILayout.Label("当前鼠标Y轴的位置" + Input.mousePosition.y);
}
}