当前位置:网站首页>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;
}
边栏推荐
- Installation and configuration of Spark and related ecological components - quick recall
- 动态数组-vector
- 开心一下,9/28名场面合集
- 6.统一记录日志
- 一篇文章彻底理解Redis的持久化:RDB、AOF
- Network Security Packet Capture
- Manifest merger failed : Attribute [email protected] value=
- mysql学习总结 & 索引
- 第三十三章:图的基本概念与性质
- Introduction to C language function parameter passing mode
猜你喜欢

网络安全抓包

What should I do if the Win10 system sets the application identity to automatically prompt for access denied?

Win10 Settings screen out from lack of sleep?Win10 set the method that never sleep

mysql的索引结构为什么选用B+树?

如何用硬币模拟1/3的概率,以及任意概率?

剑指offer:删除链表中重复的节点

Win10 computer can't read U disk?Don't recognize U disk how to solve?

测试用例练习

倍增和稀疏表

Introduction to C language function parameter passing mode
随机推荐
永久更改pip源
Doubled and sparse tables
Win10 computer can't read U disk?Don't recognize U disk how to solve?
倍增和稀疏表
Cmd Markdown 公式指导手册
第三十一章:二叉树的概念与性质
富文本编辑
MATLAB制作简易小动画入门详解
Masters and Masters
Configure clangd for vscode
Failed to install using npx -p @storybook/cli sb init, build a dedicated storybook by hand
模板系列-并查集
Manifest merger failed : Attribute [email protected] value=
模板系列-二分
The SSE instructions into ARM NEON
LeetCode 2344. 使数组可以被整除的最少删除次数 最大公约数
6. Unified logging
Compilation error D8021: Invalid numeric argument '/Wextra' cl command line error d8021 invalid numeric argument '/Wextra'
pygame draw arc
基于矩阵计算的线性回归分析方程中系数的估计