关于画线插件Vectrosity

想实现功能就是在点击两点有画出一个线段的功能。在网上找了好多的代码,就是vectrosity插件的坑。这里写图片描述
这个是其他人写的,但是你复制粘贴过来会发现VectorLine里的linePoints会报错,说vector[]2不能转换list《vector2》。
这里写图片描述
是不是应为版本不同?我用的插件版本是这里写图片描述
下面是我用插件写的效果,先付图:
这里写图片描述
效果和line renderer的效果是差不多的,但是插件的功能不止如此,还在研究当中。下面是代码:

using System.Collections.Generic;
using UnityEngine;
using Vectrosity;

public class MyDrawLine : MonoBehaviour
{

private VectorLine line;
private List<Vector3> points;
Ray r;
RaycastHit hit;
//是否是第一个点击的点
private bool Isonepoint=false;

void Start()
{
    points = new List<Vector3>();

    line = new VectorLine("Line", points, null,5f);
    Isonepoint = true;
}


void Update()
{
    //points[1] = new Vector3(Input.mousePosition);
    //第一个鼠标的点;

    if (Input.GetMouseButtonDown(0))
    {
        print("点击第一个点");
        r = Camera.main.ScreenPointToRay(Input.mousePosition);
        if (Physics.Raycast(r, out hit, 1000f))
        {
            print(hit.collider.name);
            if (Isonepoint)
            {
                print("我要点击第一个点");
                points.Add(new Vector3(hit.point.x, hit.point.y, hit.point.z));
                //points[0];
                Isonepoint = false;
                print(points[0]);
            }
            else
            {
                print("我要点击第二个点");
                //points[1] = new Vector3(hit.point.x, hit.point.y, hit.point.z);
                points.Add(new Vector3(hit.point.x, hit.point.y, hit.point.z));
                print(points[1]);
                Isonepoint = true;
            }

           // Vector3 v= line.GetPoint3D(Vector3.Distance(points[0], points[1]));
           // print(v);
            line.Draw();
        }
    }

    //line.Draw3D();

}

}

插件链接:
链接:https://pan.baidu.com/s/1W7LNDUxPYxpoUz6MpM0GIg 密码:g7rg
声明:插件是包中包,具体看详细的What to import!的txt文件,包中有。

猜你喜欢

转载自blog.csdn.net/qq_41505689/article/details/81221923