当前位置:网站首页>【Unity技术积累】实现鼠标画线功能 & LineRenderer
【Unity技术积累】实现鼠标画线功能 & LineRenderer
2022-07-17 11:57:00 【FYK0q0】
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Painting : MonoBehaviour
{
private LineRenderer lineRenderer;
// 记录点
private Vector3 nowPos;
// 线条宽度
public float lineWidth = 0.5f;
// 设置材质
public Material material;
private void Update()
{
// 鼠标按下时起点位置切换
if (Input.GetMouseButtonDown(0))
{
// 创建空物体并且添加组件
GameObject obj = new GameObject();
lineRenderer = obj.AddComponent<LineRenderer>();
//关闭自动缝合
lineRenderer.loop = false;
// 设置线条宽度
lineRenderer.startWidth = lineWidth;
lineRenderer.endWidth = lineWidth;
// 设置点数量为0
lineRenderer.positionCount = 0;
// 设置线条材质
lineRenderer.material = material;
// 设置材质收到光线影响
lineRenderer.generateLightingData = true;
}
// 画的时候鼠标是一直按下的状态
if (Input.GetMouseButton(0))
{
lineRenderer.positionCount += 1;
// 记录鼠标位置
nowPos = Input.mousePosition;
// 设置横切面为10
nowPos.z = 10;
// 设置点
// 鼠标位置视口坐标转成世界坐标
lineRenderer.SetPosition(lineRenderer.positionCount
- 1, Camera.main.ScreenToWorldPoint(nowPos));
}
}
}

边栏推荐
- The module created by yourself uses CMD to open the report modulenotfounderror: no module named solution
- English grammar_ Personal pronoun usage
- 中科磐云—D模块web远程代码执行漏洞解析
- Good news
- mof定制材料|超薄MOF纳米带|磁性Fe3O4 @Cd-MOF纳米复合材料|ZIF-8/石墨烯复合纳米颗粒
- 笔记本键盘失灵解决办法
- Brilliant use output
- 2022年湖南省中职组“网络空间安全”赛题解析(超详细)
- 死锁、线程与进程讲解
- Simulation Research on optimal detection of fault data in communication network
猜你喜欢

Rhcsa day 1 7.11

pfSense配置Tailscal站点到站点连接

【C语言】浅涉第一个C语言程序及数据类型

Online education knowledge payment website source code system + live broadcast + applet, installation tutorial

华为无线设备配置智能漫游

Pfsense configure tailscal site to site connection

TLS four handshakes

JMeter中如何实现接口之间的关联?

华为无线设备配置动态负载均衡

Software engineering - ranking of majors in Chinese Universities of Software Science
随机推荐
Microsoft OneNote 教程,如何在 OneNote 中插入数学公式?
【分离式超图像分类平台】使用深度学习中那些令人兴奋的模型搭建图像分类平台
【C语言】字符串、转义字符及注释
2022-07-16: what is the output of the following go language code? A:[]; B:[5]; C:[5 0 0 0 0]; D:[0 0 0 0 0]。 package main imp
半监督学习在恶意软件流量检测中的应用
2022年湖南 省中职组“网络空间安全”Windows渗透测试 (超详细)
GIS数据漫谈(三)
Browser story
【C语言】浅涉常量、变量
TP5 judgment request mode
Rhcsa day 1 7.11
软件工程——软科中国大学专业排名
上学=挣钱?无需缴纳学费的神仙院校!
荔枝音质高保真AI降噪技术分享
Talking about the informatization planning of industrial enterprises
Blender自动化建模入门
Relationship between standardization, normalization and regularization
laravel 生成分表脚本示例
Data Lake (XII): integration of spark3.1.2 and iceberg0.12.1
Machine learning basics that can be easily introduced in 5 minutes