Line Renderer是unity提供的用来方便地绘制线条的组件。
通过指定线条的每一个节点位置即可绘制出一条折线,可以在Inspection的Position中设定每个节点的位置,Position[0]位start,Position[Length-1]为end,也可以在脚本中使用如下代码指定折线节点位置。
Vector3[] positions = new Vector3[3];
positions[0] = new Vector3(-2.0f, -2.0f, 0.0f);
positions[1] = new Vector3(0.0f, 2.0f, 0.0f);
positions[2] = new Vector3(2.0f, -2.0f, 0.0f);
lineRenderer.positionCount = positions.Length;
lineRenderer.SetPositions(positions);
可以在Inspection设定颜色信息,也可以在脚本中使用startColor,endColor修改颜色。
需要添加指定材质,推荐使用 New Material(Shader.Find("Sprites/Default")),PBR材质不会受到设定的颜色的影响。
参考LineRenderer Manual:https://docs.unity.cn/cn/current/Manual/class-LineRenderer.html
LineRenderer API:
Unity中LineRenderer组件详解

本文详细介绍了Unity中LineRenderer组件的使用方法,包括如何设置节点位置和颜色,以及如何控制线条宽度。LineRenderer组件允许开发者通过指定一系列点来创建折线,并提供了脚本和编辑器界面两种设置方式。
最低0.47元/天 解锁文章
8940

被折叠的 条评论
为什么被折叠?



