首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何清除LineRenderer路径来重画线条?

如何清除LineRenderer路径来重画线条?
EN

Stack Overflow用户
提问于 2017-12-26 23:46:58
回答 1查看 12.3K关注 0票数 3

我有一个LineRenderer路径来显示GolfBall的路径。请看图中的栗色路径。

代码语言:javascript
复制
private void createTrail()
{
    lineRenderer.SetColors(tracerColor, tracerColor);
    lineRenderer.SetVertexCount(maxVertexCount);
    for (int idx = 0; idx < (maxVertexCount - 2); idx++)
    {//Add another vertex to show ball's roll
        lineRenderer.SetPosition(idx, new Vector3((float)pts[idx * (int)positionSampling].z, (float)pts[idx * (int)positionSampling].y, (float)pts[idx * (int)positionSampling].x));
    }
    lineRenderer.SetPosition(maxVertexCount - 2, new Vector3((float)pts[goal - 1].z, (float)pts[goal - 1].y, (float)pts[goal - 1].x));
    lineRenderer.SetPosition(maxVertexCount - 1, transform.position);
}

路径是使用pts[] array中的点绘制的。

在重复显示时,我需要清除旧路径以重新绘制相同的路径。我怎样才能清除这条旧路?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-12-27 00:06:39

LineRenderer没有清除函数,您不需要清除它就可以重新绘制它。而且,LineRenderer不需要手动重新绘制。这是由Unity处理的。

如果您的目标是重置您设置的旧顶点位置,只需将LineRenderer的顶点计数设置为0。您可以使用SetVertexCount(0)函数或positionCount变量来执行此操作。请注意,SetVertexCount现在已被弃用。

这将删除您设置为LineRenderer的所有行

代码语言:javascript
复制
LineRenderer.positionCount = 0;

的扩展方法:

代码语言:javascript
复制
public static class ExtensionMethod
{
    public static void Reset(this LineRenderer lr)
    {
        lr.positionCount = 0;
    }
}

现在,您可以调用lineRenderer.Reset()来重置您之前设置的所有位置/路径。

票数 8
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47980803

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档