关于unity画线插件Vectrosity(二)

昨天研究的那个画线只是画屏幕上了,切到scence视图就很明显,并没有形成空间的线。要想做空间的线怎么弄呢?先上图:
这里写图片描述这里写图片描述
这里写图片描述
废话也不多说,直接上代码:
using System.Collections.Generic;
using UnityEngine;
using Vectrosity;
public class MyDrawLine : MonoBehaviour
{
Ray r;
RaycastHit hit;
//private bool Isonepoint=false;
private VectorLine l;
private Vector3[] points;
void Start()
{
//定义一个数组,但是为啥是两个长度的呢?一会在解释
points = new Vector3[2];
}
void Update()
{
points[0] = transform.position;
if (Input.GetMouseButtonDown(0))
{
r = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(r, out hit, 1000f))
{
points[1] = hit.point;
}
l = VectorLine.SetLine3D(Color.black, 50f, points);
l.Draw();
}
}
}
先看下setline3d有哪些重载:
这里写图片描述
还是很多的,可以满足各种要求。
现在我们说一下,这里我为什么定义数组的长度是2了。数学里定义一条线段是两个点可以确定一条线段,那么程序里也要这么写,至于数组写的长,大家可以自己去尝试,我这里只是举个例子,适合新人去学。我这里写了个cube移动的脚本,大家可以自己去玩玩。

猜你喜欢

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