当前位置:网站首页>[unity technology accumulation] realize the mouse line drawing function &linerenderer
[unity technology accumulation] realize the mouse line drawing function &linerenderer
2022-07-19 11:40:00 【FYK0q0】
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Painting : MonoBehaviour
{
private LineRenderer lineRenderer;
// Record point
private Vector3 nowPos;
// Line width
public float lineWidth = 0.5f;
// Set the material
public Material material;
private void Update()
{
// When the mouse is pressed, the starting position switches
if (Input.GetMouseButtonDown(0))
{
// Create an empty object and add components
GameObject obj = new GameObject();
lineRenderer = obj.AddComponent<LineRenderer>();
// Turn off automatic stitching
lineRenderer.loop = false;
// Set line width
lineRenderer.startWidth = lineWidth;
lineRenderer.endWidth = lineWidth;
// Set the number of points to 0
lineRenderer.positionCount = 0;
// Set line material
lineRenderer.material = material;
// Set the material to be affected by light
lineRenderer.generateLightingData = true;
}
// When drawing, the mouse is pressed all the time
if (Input.GetMouseButton(0))
{
lineRenderer.positionCount += 1;
// Record the mouse position
nowPos = Input.mousePosition;
// Set the cross section to 10
nowPos.z = 10;
// Set point
// Mouse position viewport coordinates into world coordinates
lineRenderer.SetPosition(lineRenderer.positionCount
- 1, Camera.main.ScreenToWorldPoint(nowPos));
}
}
}

边栏推荐
- ZABBIX proxy server configuration
- How to change and reset forgotten root password in RHEL 9
- 03-1. Inline function, auto keyword, typeID, nullptr
- 02 - 3. Différences entre les pointeurs et les références
- Wechat applet cloud development 1 - Database
- 公网连接MySQL实例的解决方案
- Synchronized lock upgrade
- 02-2. Default parameters, function overloading, reference, implicit type conversion, about error reporting
- Transport layer -------- TCP (I)
- 学习笔记3--规划控制中的机器学习基本思想
猜你喜欢

Qt--优秀开源项目

华为无线设备配置频谱导航

Robot development -- common simulation software tools

Will causal learning open the next generation of AI? Chapter 9 Yunji datacanvas officially released the open source project of ylarn causal learning

Download of common getshell tools

Leetcode 1304. N different integers with zero and

热议:老公今年已经34周岁想读博,以后做科研,怎么办?

Tire Defect Detection Using Fully Convolutional Network-论文阅读笔记

【PostgreSQL 】PostgreSQL 15对distinct的优化

Leetcode 1328. Destroy palindrome string (yes, solved)
随机推荐
02-2. Default parameters, function overloading, reference, implicit type conversion, about error reporting
The difference between CPU load and CPU utilization
Huawei firewall authentication technology
02-3. Difference between pointer and reference
设置cmd命令提示符窗口的界面语言为英文
Antd form setting array fields
LeetCode 558. Intersection of quadtree
TiKV 内存参数性能调优
466-82(3、146、215)
Keras deep learning practice (14) -- r-cnn target detection from scratch
机器人开发--常用仿真软件工具
Kunlunbase online meetup is waiting for you~
开发那些事儿:如何解决RK芯片视频处理编解码耗时很长的问题?
function/symbol ‘pango_context_set_round_glyph_positions‘ not found in library ‘libpango-1.0.so.0‘x
Some methods of early MCU encryption [get data in the comment area]
How to change and reset forgotten root password in RHEL 9
At5147-[agc036d]negative cycle [DP, model conversion]
【二叉树】之力扣牛客必刷题
A simple output method of promise object to the result in nodejs (it is recommended to use the asynchronous ultimate scheme async+await)
Qt--优秀开源项目