当前位置:网站首页>Unity Line-Renderer
Unity Line-Renderer
2022-08-02 14:11:00 【莉萝爱萝莉】
绘制线条的组件
1. 参数列表
参数名 | 描述 |
---|---|
大小 | 绘制线条关键点的数量,将点依次连接 |
颜色 | 绘制线条的颜色 |
角顶点 | 折点处顶点数量 |
末端顶点 | 末端处顶点数量 |
2. 代码参数列表
// 新建一条线
GameObject go = new GameObject();
go.AddComponent<LineRenderer>();
参数名 | 描述 |
---|---|
material | 材质 |
startWidth | 起始宽度 |
endWidth | 末端宽度 |
startColor | 起始颜色 |
endColor | 末端颜色 |
numCornerVertices | 角顶点 |
numCapVertices | 末端顶点 |
positionCount | 顶点数量 |
2. 函数列表
参数名 | 描述 |
---|---|
SetPositions(Vector3[]) | 顶点集合 |
3. 画笔示例
// 画笔颜色
[SerializeField] Color paintColor = Color.red;
// 画笔宽度
[SerializeField] float paintSize = 0.2f;
// 画笔材质
[SerializeField] Material lineMaterial;
LineRenderer currentLine;
List<Vector3> positions = new List<Vector3>();
bool IsMouseDown = false;
public void ChangeColor(int value)
{
if(value == 0)
paintColor = Color.red;
if (value == 1)
paintColor = Color.green;
if (value == 2)
paintColor = Color.blue;
}
public void ChangeSize(float pse)
{
paintSize = pse;
}
private void Update()
{
if (Input.GetMouseButtonDown(0))
{
GameObject go = new GameObject();
go.transform.SetParent(this.transform);
currentLine = go.AddComponent<LineRenderer>();
currentLine.material = lineMaterial;
currentLine.startWidth = paintSize;
currentLine.endWidth = paintSize;
currentLine.startColor = paintColor;
currentLine.endColor = paintColor;
currentLine.numCornerVertices = 5;
currentLine.numCapVertices = 5;
positions.Clear();
AddPosition();
IsMouseDown = true;
}
if(IsMouseDown)
{
AddPosition();
}
if (Input.GetMouseButtonUp(0))
{
IsMouseDown = false;
}
}
void AddPosition()
{
Vector3 position = GetMousePoint();
positions.Add(position);
currentLine.positionCount = positions.Count;
currentLine.SetPositions(positions.ToArray());
}
Vector3 GetMousePoint()
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
bool flag = Physics.Raycast(ray, out hit);
if(flag)
{
return hit.point - Vector3.forward / 100;
}
return Vector3.zero;
}
边栏推荐
- Win10 computer can't read U disk?Don't recognize U disk how to solve?
- 深入理解Golang之Map
- 第二十九章:树的基本概念和性质
- KiCad常用快捷键
- Use libcurl to upload the image of Opencv Mat to the file server, based on two methods of post request and ftp protocol
- Cmd Markdown 公式指导手册
- 5. Transaction management
- MATLAB绘图命令fimplicit绘制隐函数图形入门详解
- Mysql之MVCC
- 6.统一记录日志
猜你喜欢
随机推荐
队列与栈
Failed to install using npx -p @storybook/cli sb init, build a dedicated storybook by hand
Masters and Masters
轻量化AlphaPose
KiCad常用快捷键
基于最小二乘法的线性回归分析方程中系数的估计
Yolov5 official code reading - prior to transmission
专硕与学硕
[System Design and Implementation] Flink-based distracted driving prediction and data analysis system
永久更改pip源
求解斐波那契数列的若干方法
Spark及相关生态组件安装配置——快速回忆
MATLAB绘图命令fimplicit绘制隐函数图形入门详解
质数相关问题-小记
Detailed explanation of Golang garbage collection mechanism
Cmd Markdown 公式指导手册
5.事务管理
Project: combing the database table
剑指offer:删除链表中重复的节点
Introduction to MATLAB drawing functions ezplot explanation