当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
随机推荐
How to simulate 1/3 probability with coins, and arbitrary probability?
LeetCode 2353. 设计食物评分系统 维护哈希表+set
二叉树遍历之后序遍历(非递归、递归)入门详解
剑指offer:删除链表中重复的节点
专硕与学硕
4. Publish Posts, Comment on Posts
How to solve Win11 without local users and groups
GMP scheduling model of golang
Open the door of electricity "Circuit" (1): voltage, current, reference direction
开心一下,9/28名场面合集
质数相关问题-小记
背包问题-动态规划-理论篇
利用plot_surface命令绘制复杂曲面入门详解
极简式 Unity 获取 bilibili 直播弹幕、SC、上舰、礼物等 插件
[STM32 Learning 1] Basic knowledge and concepts are clear
TCP三次握手、四次挥手
2.登录退出,登录状态检查,验证码
MATLAB绘图函数plot详解
Based on the matrix calculation in the linear regression equation of the coefficient estimates
Unity-编辑器扩展(Editor)