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

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中的点绘制的。
在重复显示时,我需要清除旧路径以重新绘制相同的路径。我怎样才能清除这条旧路?
发布于 2017-12-27 00:06:39
LineRenderer没有清除函数,您不需要清除它就可以重新绘制它。而且,LineRenderer不需要手动重新绘制。这是由Unity处理的。
如果您的目标是重置您设置的旧顶点位置,只需将LineRenderer的顶点计数设置为0。您可以使用SetVertexCount(0)函数或positionCount变量来执行此操作。请注意,SetVertexCount现在已被弃用。
这将删除您设置为LineRenderer的所有行
LineRenderer.positionCount = 0;的扩展方法:
public static class ExtensionMethod
{
public static void Reset(this LineRenderer lr)
{
lr.positionCount = 0;
}
}现在,您可以调用lineRenderer.Reset()来重置您之前设置的所有位置/路径。
https://stackoverflow.com/questions/47980803
复制相似问题