关于画线插件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文件,包中有。

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 8
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值