当前位置:网站首页>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;
}
边栏推荐
- 1. Development community homepage, register
- 奇技淫巧-位运算
- STM32LL库——USART中断接收不定长信息
- Installation and configuration of Spark and related ecological components - quick recall
- 使用libcurl将Opencv Mat的图像上传到文件服务器,基于post请求和ftp协议两种方法
- Mysql之MVCC
- Configure clangd for vscode
- General code for pytorch model to libtorch and onnx format
- 测试用例练习
- 远程连接Ubuntu中的Mysql
猜你喜欢
第二十五章:一文掌握while循环
动态规划理论篇
What are IPV4 and IPV6?
pygame绘制弧线
倍增和稀疏表
Installation and configuration of Spark and related ecological components - quick recall
剑指offer:数值的整数次方
基于最小二乘法的线性回归分析方程中系数的估计
Detailed introduction to drawing complex surfaces using the plot_surface command
flink+sklearn——使用jpmml实现flink上的机器学习模型部署
随机推荐
pygame图像连续旋转
二叉树遍历之后序遍历(非递归、递归)入门详解
How to update Win11 sound card driver?Win11 sound card driver update method
MATLAB图形加标注的基本方法入门简介
LeetCode 2344. 使数组可以被整除的最少删除次数 最大公约数
C语言函数参数传递模式入门详解
Software Testing Basics (Back)
Failed to install using npx -p @storybook/cli sb init, build a dedicated storybook by hand
Installation and configuration of Spark and related ecological components - quick recall
第二十八章:解题技巧
Codeforces Round #605 (Div. 3)
Introduction to MATLAB drawing functions ezplot explanation
第三十章:普通树的存储和遍历
面试汇总
Detailed explanation of Golang garbage collection mechanism
6. Unified logging
Configure clangd for vscode
Fast advanced TypeScript
Open the door of power and electricity "Circuit" (2): Power Calculation and Judgment
3. User upload avatar