c# - 如何统一获取线渲染器的所有点位置?
问题描述
我想获取线渲染器线中的所有点位置,我需要这些点位置,因为我想逐行绘制线渲染器,然后让球在这条线上移动,所以我想使用线的点位置移动这个球到画完后让球在这条线上移动
这是我使用线条渲染器绘制线条的代码
public LineRenderer lineRend;
public EdgeCollider2D edgeColl;
List <Vector2> points;
public void Update_line(Vector2 mouse_pos)
{
if (points == null)
{
points = new List<Vector2> ();
set_point(mouse_pos);
return;
}
if (Vector2.Distance(points[points.Count - 1], mouse_pos) > .1f)
{
set_point(mouse_pos);
}
}
void set_point(Vector2 point)
{
points.Add(point);
lineRend.positionCount = points.Count;
lineRend.SetPosition(points.Count - 1, point);
if (points.Count > 1)
{
edgeColl.points = points.ToArray();
}
}
}
下图说明了我想在我的游戏中做什么,位于图像底部的球我希望它在画线上移动
那么我必须通过代码执行此操作吗?
解决方案
lineRend.GetPositions(out Vector3[] allPoints);
GetPositions
在 out 变量中返回线渲染器上的所有点。它的数组Vector3
https://docs.unity3d.com/ScriptReference/LineRenderer.GetPositions.html
推荐阅读
- bash - 每天计算多个文件中的错误消息
- javascript - 电子登录助手不起作用 - “进程不在继承的沙箱中”
- ios - 点击屏幕会导致当前控制器返回到前一个控制器
- android - 如何解决cordova应用程序突然崩溃的问题?
- apache - 使用 VirtualHost 将 HTTP 重定向到 HTTPS
- yaml - Jekyll 默认(布局) Front Matter 不起作用:已修复
- python - 创建循环以通过多个 URL 导入数据
- updates - 错误:无法验证更新。确保网络安全,然后重试。
- javascript - 找不到模块:错误:无法解析“croppie”
- sql-server - 查询和子查询遇到问题:SQL 子查询返回超过 1 个值