c# - 无法在 Unity 中将路径点与线渲染器连接起来
问题描述
我正在尝试生成一个路径系统,其中一条线随着时间的推移而呈现。我的代码是:
public IEnumerator DrawPath(List<Vector3> pathWay)
{
lineRenderer.positionCount = 0;
points = new Vector3[pathWay.Count];
for (int i = 0; i < pathWay.Count; i++)
{
Vector3 checkpointpos = pathWay[i];
points[i] = new Vector3(checkpointpos.x, checkpointpos.y, checkpointpos.z);
}
lineRenderer.startWidth = 1f;
lineRenderer.endWidth = 1f;
lineRenderer.positionCount = points.Length;
for (int i = 0; i < points.Length; i++)
{
//Mathf.Lerp
yield return new WaitForSeconds(0.1f);
lineRenderer.SetPosition(i, points[i]);
}
}
输出:
我List<Vector3>
从 A* Pathfinding 免费版插件中获得。任何形式的帮助将不胜感激。提前致谢。
解决方案
好的,我解决了这个问题。
问题是一次设置行数,所以每当我设置一个新向量时,它从位置 0 开始,这就是我遇到问题的原因。
解决方案:
public IEnumerator DrawPath(List<Vector3> pathWay)
{
lineRenderer.positionCount = 0;
points = new Vector3[pathWay.Count];
lineRenderer.startWidth = 1f;
lineRenderer.endWidth = 1f;
for (int i = 0; i < pathWay.Count; i++)
{
Vector3 checkpointpos = pathWay[i];
points[i] = new Vector3(checkpointpos.x, checkpointpos.y, checkpointpos.z);
yield return new WaitForSeconds(0.1f);
lineRenderer.positionCount++;
lineRenderer.SetPosition(i, points[i]);
}
}
输出:
推荐阅读
- html - 如何将shopify cdn转换/集成到引导程序
- html - 如何将网站的桌面视图强制到移动设备上
- angular - pdfmake,TypeError:无法分配给字符串的只读属性“0”
- sql-server - Powershell invoke-sqlcmd 打印错误的输出
- visual-studio - 如何轻松更改 Visual Studio 2022 编辑器字体和颜色以匹配 VS 2019
- python - 为什么我会收到“logits and label must have the same shape”错误?
- flutter - 为什么 gridview 在 Flutter 中重新加载图像?
- puppet - 如何处理依赖于 gem 模块的自定义 Puppet 事实?
- android - 创建了一个新模块,但扩展函数显示错误:无法访问 'java.io.Serializable' 这是 'kotlin.String' 的超类型
- opa - 从一个集合中检索一个值,其中密钥来自开放策略代理 (OPA) 中的另一个集合